4 ms·
I get 10ms to cluster and segment an image with tuned numpy and opencv. With better results. Indeed the loops regarding the inner patch convolution are the kill
by tlarkworthy 14y ago
I get 10ms to cluster and segment an image with tuned numpy and opencv. With better results. Indeed the loops regarding the inner patch convolution are the killer. I used fingmineig, corner detectors, to turn a pixel location into a vector of corners at different spatial scales. Those routines are performed in parralell on opencv so I got rid of the inner patch kernel and it all delegates to blas. No loops
- nightski 14y agoI'd say that yes, if you are just performing an operation that already exists in a common C library just use that. But I could see the advantages for an algorithm that did not already exist for which you wanted to express in Python. OpenCV is great as a black box but its built in functions are not always sufficient or optimal.
- onalark 14y agoI'm always interested in working with practical examples. Do you have some sample code I could look at?
- tlarkworthy 14y agoEDIT: Formatting is a bit whacked. I have two consecutive frames of a sonar image (same size) as the input, you will have to exchange those parts but I ran it fine. There are more parameters in the "DEFAULT_PARAMS" dict as I copied this from a much larger program. I work in greyscale so that might actually be a problem for genralization. EDIT2: deleted as the src has been truncated, http://pastebin.com/dPMsRF78 http://pastebin.com/dPMsRF78
- onalark 13y agoSorry, I missed this reply earlier, I'll take a look at it today.
- onalark 13y agoHi tlarkworthy, thanks for sharing your code with me! - It's really hard to make valid comparisons against data I don't have access to. Do you have any open data sets to try this comparison against? - It looks like the meat of the work is being done here by scikit-learn. As was mentioned earlier, Numba at this stage is mostly useful for improving kernel performance, not large library routines. I'm planning on taking a deeper look into some of the scikit-learn kernels in the future. Keep an eye open for a blog post from Continuum on this.
- tlarkworthy 13y agoOK these are the images, feel free to replicate them distribute them, whatever, there is no licensing.:- http://img716.imageshack.us/img716/5808/frame0108.jpg http://img716.imageshack.us/img716/5808/frame0108.jpg and http://img254.imageshack.us/img254/9562/frame0109.jpg http://img254.imageshack.us/img254/9562/frame0109.jpg Yeah I use openCV and scikit learn to do the heavy lifting indeed. But then if I used Numba surely that is what you are advocating too?? I tried unrolling the inner kernel a few different ways before settling on the code you have before you. It doesn't compute the feature vector exactly how I would want, BUT ITS really FAST, which for sonar analysis to run on AUV in real time that's essential. I will fit my math to the library to meet my CPU budgets. Anyway I hope you can use this as a benchmark or something even if its implemented in a totally different way than you might do. feel free to email me tom dot larkworthy <at> gmail Tom
- tlarkworthy 13y agooh I should also add that the clustering (kmeans) is very fast. The analogous part to the inner loop is "feature_vectors". Which has 2 main cases: case 1, in the case nothing has been computed it calculates the corner response images at all the different spatial scales (big operations). case 2, feature_vector just selects data from the corner images for the pixels demanded. Now my algorithm is sparse so its normally jsut selecting a subset of pixels, although as it calculated the spatial responses of the whole image it doesn't really make any odds to my runtime.
- 13y ago