gattia / cycpd Goto Github PK
View Code? Open in Web Editor NEWCython implementation of Coherent Point Drift (CPD)
License: MIT License
Cython implementation of Coherent Point Drift (CPD)
License: MIT License
Add black (or another formatter) to the build pipeline so that things stay consistent?
Use Flake8 to to lint?
enable badge on the current status of master.
should we include pull requests here too?
But add flag in badge that only for master & push?
can these all be in one but with separate badges w/ the different flags?
Can't remember why specific numpy version was pinned. Should be able to fix this to be any numpy version... Currently limiting to max python 3.10 becuase 3.11 does not have the appropriate version of numpy released.
This can be seen in the examples where the affine registration just stays its current shape and finds the optimal deformation.
In the Rigid/Affine deformations, they are first squashed to be tiny, and then they slowly grow to be the optimal size. Is this a bug?
change verbosity / print_reg_params so that verbose takes multiple levels, higher levels will print the reg_params
Hi,
I'm not quite sure how to go about debugging this - but I wonder if the imports within the library need to be changed. When using the library via another module (say a relatively simply wrapper like this:)
from cycpd import affine_registration
def affine_cpd(X, Y, max_iterations=100, init_only=False):
reg = affine_registration(**{'X': X, 'Y': Y, 'max_iterations': max_iterations, 'print_reg_params': False, 'verbose': False})
# B is the rotation matrix, t is the translation vector
if not init_only:
B, t = reg.register()
return reg
...this error occurs:
File "cycpd\cython\cython_functions.pyx", line 209, in cython_functions.__pyx_fused_cpdef
TypeError: No matching signature found
Is there anything obviously wrong here? Library installed via: pip install cycpd
Hi. Thank you for your implementation using Cython.
I am using your code for pointcloud registration where multiple pointclouds should be registered, so I use ray to parallelize my code.
I encountered a small issue but I found the solution here: https://github.com/dask/distributed/issues/1978
So I add this function above the definition of class "expectation_maximization_registration";
def _memoryview_safe(x):
"""Make array safe to run in a Cython memoryview-based kernel. These
kernels typically break down with the error ``ValueError: buffer source
array is read-only`` when running in dask distributed.
"""
if not x.flags.writeable:
if not x.flags.owndata:
x = x.copy(order='C')
x.setflags(write=True)
return x
and modify the functions "register" and "expectation" in expectation_maximization_registration.py
def register(self, callback=lambda **kwargs: None):
tic = time.time()
self.transform_point_cloud()
self.X = _memoryview_safe(self.X)
self.Y = _memoryview_safe(self.Y)
self.sigma2 = cy.initialize_sigma2(self.X, self.Y)
......
def expectation(self):
self.X = _memoryview_safe(self.X)
self.TY = _memoryview_safe(self.TY)
self.P1, self.Pt1, self.PX, self.Np, self.E = cy.expectation_2(self.X,
self.TY,
self.sigma2,
self.M,
self.N,
self.D,
self.w)
Another small issue is that I have to convert my pointcloud numpy array (np.float64) into array of dtype np.double to avoid the TypeError: No matching signature found when using ray to parallelize the code, but it works well without using ray. I am not sure maybe that's an issue of ray since I am not familiar with Cython.
Look into using pyproject.toml
like described in pull request: #4
Alternatively, should make
be used for packaging?
Hi. I find that you do not return the probability matrix P (shape=(M,N)) when you calculate the expectation using funtion expectation_2 in your cython code.
Does it slow down the entire registration?
Also I have to analyze that matrix in my following step. Could you please help me check whether my modifcation is coorect? It seems right during my execution.
@cython.boundscheck(False) # Deactivate bounds checking
@cython.wraparound(False) # Deactivate negative indexing.
@cython.cdivision(True) # Do division using C?
def expectation_3(my_type[:,:] X, my_type[:,:] TY, my_type sigma2, int M, int N, int D, double w):
# TY is MxD (same as Y - it is just transformed Y). M = rows of points Y, and D is dimensions.
# tic = time.time()
# cdef Py_ssize_t x_i_shape, x_j_shape, y_i_shape, y_j_shape
if my_type is double:
dtype = np.double
cdef Py_ssize_t n, m, d # i, j, k
cdef double ksig, diff, w_tmp, den, tmp_total, Np, E # den = sp in original matlab, tmp_total = razn
# cdef double [:] temp_x
temp_x = np.zeros(D, dtype=np.double)
cdef double [:] temp_x_view = temp_x
ksig = -2.0 * sigma2
w_tmp = (w * M * c_pow(-ksig * 3.14159265358979,0.5*D))/((1-w)*N) # c in the original manuscript
cdef my_type[:, :] X_view = X
cdef my_type[:, :] TY_view = TY
probP = np.zeros((M, N), dtype=dtype)
cdef my_type[:,:] probP_view = probP
# Make P array
# cdef my_type[:] P
P = np.zeros(M, dtype=dtype)
cdef my_type[:] P_view = P
# Make P1 array
# cdef my_type[:] P1
P1= np.zeros(M, dtype=dtype)
cdef my_type[:] P1_view = P1
# Make Pt1 array
# cdef my_type[:] Pt1
Pt1= np.zeros(N, dtype=dtype)
cdef my_type[:] Pt1_view = Pt1
# Make Pt1 array
# cdef my_type[:, :] Px
Px= np.zeros((M, D), dtype=dtype)
cdef my_type[:, :] Px_view = Px
for n in range(N):
den = 0
for m in range(M):
tmp_total = 0
for d in range(D):
diff = X_view[n, d] - TY_view[m, d]
diff = diff * diff
tmp_total += diff
P_view[m] = c_exp(tmp_total/ksig)
probP_view[m, n] = c_exp(tmp_total/ksig)
den += P_view[m]
den += w_tmp
for m in range(M):
probP_view[m, n] = probP_view[m, n] / den
Pt1_view[n] = 1-w_tmp/den
for d in range(D):
temp_x_view[d] = X_view[n, d] / den
for m in range(M):
P1_view[m] += P_view[m] / den
for d in range(D):
Px_view[m, d] += temp_x_view[d] * P_view[m]
E += -c_log(den)
Np = 0
for m in range(M):
Np += P1_view[m]
E += D * Np * c_log(sigma2)/2
return probP, P1, Pt1, Px, Np, E
Travis CI free tier has run out. Need to choose an alternative option for testing pull/merge requests. Seems like github actions might be the best option?
Here's one blog comparing Circle-CI with GHA. https://earthly.dev/blog/migrating-from-travis/
Instruction on how to keep GHA up to date here:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.