Use fused types in denoise, warp#3486
Conversation
|
Hello @jni! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-03-05 23:40:45 UTC |
|
Why is OSX failing? https://travis-ci.org/scikit-image/scikit-image/jobs/443575582#L5300 |
AetherUnbound
left a comment
There was a problem hiding this comment.
Looks good to me - thanks for compiling this all together! And thanks @hmaarrfk for fixing the negative indexing stuff.
|
@jni, I'm going to say that though I appreciate that my original PR is taken seriously, I don't know how worthwhile it is to complicate the warping code if it doesn't really give a speedup. In my experience, templated code is so much harder to read and to adapt. By including this, we are forcing future developers to also develop warping algorithms that function for all numeric types. This is a huge potential burden. I would look into why it was that any speedup was obtained for float64 types and maybe just apply that fix. It might have been passing a parameter by reference in a tight loop which was necessary to template the functions. I think the assumption that integer arithmetic is faster than floatingpoint is seriously flawed due to massive hardware optimizations for the floating point units in modern processors, though I'm not an expert in this field. float32/float64 seems to be a valid assumption if you can guarantee not upcasting. float16 only recently started to exist because GPUs are running out of memory for machine learning. I can't speak specifically for @AetherUnbound's PR, I was mostly helping with syntax. |
|
@hmaarrfk but speed is not the only advantage, there is also RAM usage, right? I think that's very valuable. And personally I don't find the code much more complicated. And you know I'm quite nitpicky about complicated code! =D It looks like the test failure is to do with random noise values. Same failure on that Mac build as on AppVeyor: Edit: here's the failure for quick reference: __________________________ test_denoise_bilateral_2d ___________________________
def test_denoise_bilateral_2d():
img = checkerboard_gray.copy()[:50, :50]
# add some random noise
img += 0.5 * img.std() * np.random.rand(*img.shape)
img = np.clip(img, 0, 1)
out1 = restoration.denoise_bilateral(img, sigma_color=0.1,
sigma_spatial=10, multichannel=False)
out2 = restoration.denoise_bilateral(img, sigma_color=0.2,
sigma_spatial=20, multichannel=False)
# make sure noise is reduced in the checkerboard cells
assert_(img[30:45, 5:15].std() > out1[30:45, 5:15].std())
> assert_(out1[30:45, 5:15].std() > out2[30:45, 5:15].std())
E AssertionError
skimage/restoration/tests/test_denoise.py:183: AssertionErrorDunno why it would happen in this PR and not elsewhere, since that test appears to use float64 anyway... Any ideas? |
|
Probably because we added some tests, the seed is different than before. Numpy (the repo) actually prints the values of the arrays that failed. Would be useful if we had that.... |
|
@hmaarrfk it's not that the seed is different, it's that it's not set. You can run repeatedly to get different results each time. |
|
@jni really? i thought the python seed was set to some consistent value everytime. I guess this isn't matlab again. It probably needs an environment variable. |
|
Anyway, perhaps it's not a good test, but it's a bit concerning that this PR brought that out. |
|
The very first time I ran it, it failed, then all other times, it passed. I even installed pytest-repeat and ran it with still passed.... |
will fail, but I can't run it with |
|
skimage/restoration/_denoise_cy.pyx
Outdated
| cdef: | ||
| double[:, :, ::1] cimage = np.ascontiguousarray(image) | ||
| double[:, :, ::1] cu = u | ||
| np_floats[:, :, ::1] cu = u |
There was a problem hiding this comment.
Can cu be removed? u is already a horrible name
|
Do we have a benchmark? is it possible to see what happens when we change the looping order of the tight loop in |
|
Finally, when all those comments are addressed, you can release the gil. You will need this line of code somewhere |
skimage/restoration/_denoise.py
Outdated
| max_value /= bins | ||
|
|
||
| for b in range(bins): | ||
| color_lut[b] = _gaussian_weight(sigma, b * max_value) |
There was a problem hiding this comment.
Python code should use numpy and not cythonisms.
|
@jni, thanks for helping find the bug. Can you please close this PR? it seems there is more work to do in the denoising PR. |
|
@hmaarrfk I don't see why the debugging needs to happens specifically in one or the other PR? I'm happy to take this on. Thanks for the detailed and specific review either way! |
|
whatever works for you and @AetherUnbound \o/ |
c73f259 to
5f78d05
Compare
|
@AetherUnbound I've given this another go. Sorry to miss your ping earlier this month. I think @hmaarrfk is on holiday in Japan atm. =D Let's see how my latest commits fare in CI! =) |
|
One last thing I want to do is move all of the LUT code out of Cython. But for now it's bedtime. |
|
It may not look like it, but CI is actually happy! 😝 🎉 🎉 🎉 @scikit-image/core can we have some reviews please? =D This fixes a regression in 0.14.1 relative to 0.14.0 so it's relatively urgent (within scikit-image levels of urgency, anyway =P). The failures are in https://travis-ci.org/scikit-image/scikit-image/jobs/461638460#L3340 |
AetherUnbound
left a comment
There was a problem hiding this comment.
Looks good to me! Beyond that test comment change
|
Ah, I don't have permission to push to your branch 😜 |
|
@AetherUnbound you don't have permission, but for future reference, you can always make a PR to my fork/branch. |
|
Also, you can probably use the "suggest" button when making comments on code...? |
|
Also, thank you very much for running the benchmarks! I have a visitor this week so I have been focusing on napari. But I agree with you that it would be excellent to push both 0.14.3 and 0.15 out the door. I think it's feasible. If we get this merged I'll devote some time today for release notes! |
|
lets just say that I used to "wait for scikit image to comile. Now I go get a coffee. |
|
@hmaarrfk this sounds like a win-win! 😂 |
|
This changes the return from Either way, this behavior change is big enough that it would require deprecation if it were to go through. |
|
@stefanv I think you've misread the PR. The output from scikit-image/skimage/transform/_warps_cy.pyx Line 138 in f9046b4 and this line is not touched. As far as the warps module is concerned, and as far as I can tell, only internal functions are touched — which might explain the benchmark results 😂. |
|
OK, so maybe I also missed the intent / benefit of this PR then. Do you mind summarizing? |
|
@stefanv the most immediate benefit is that it fixes #3449, a bug that was introduced in 0.14.1 that is preventing CellProfiler from upgrading past 0.14.0. The warping changes lay the groundwork for allowing float32 warps. Really there wouldn't be any changes to warp but we needed fused types to fix the denoise error and @hmaarrfk had already implemented them in #3253, so we built off that. |
... Hold on to your butts! =P Co-Authored-By: jni <juan.nunez-iglesias@monash.edu>
|
I think everything is in order @stefanv |
* MNT: Add a fused numeric type to make fused_types more constent. * MNT: make the interpolation use fused types for any->any type interpolation of images. * MNT: Move even more numpy function calls from Cython to Python. * MNT: More explicit type specifying * BUG: Use fused floats in denoise Pull all denoise array allocation out into python Function used in python should be def not cdef Have the correct number of arguments * MNT: Add additional type check for denoise, more docs * PEP8 fixes * Remove redundant array u and view cu * Mutate output array in Cython and trim in Python * Replace height and width with existing rows and cols * Change iteration order to match array order * Move range_lut and color_lut properly from Cy to Py * Ravel range LUT which is expected to be 1D * Update comment in denoise bilateral tests * Fix relative import in interpolation.pyx * BENCH: Benchmark for warping with many types * Rename warp benchmark file * Update pointer syntax Co-Authored-By: Mark Harfouche <mark.harfouche@gmail.com>
|
Don't ask :) |
|
I think there's very little chance that this will work but... @meeseeksdev backport to v0.14.x |
|
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
* MNT: Add a fused numeric type to make fused_types more constent. * MNT: make the interpolation use fused types for any->any type interpolation of images. * MNT: Move even more numpy function calls from Cython to Python. * MNT: More explicit type specifying * BUG: Use fused floats in denoise Pull all denoise array allocation out into python Function used in python should be def not cdef Have the correct number of arguments * MNT: Add additional type check for denoise, more docs * PEP8 fixes * Remove redundant array u and view cu * Mutate output array in Cython and trim in Python * Replace height and width with existing rows and cols * Change iteration order to match array order * Move range_lut and color_lut properly from Cy to Py * Ravel range LUT which is expected to be 1D * Update comment in denoise bilateral tests * Fix relative import in interpolation.pyx * BENCH: Benchmark for warping with many types * Rename warp benchmark file * Update pointer syntax Co-Authored-By: Mark Harfouche <mark.harfouche@gmail.com>
|
I've submitted a manual backport. |
|
@meeseeksdev backport to v0.14.x |
|
Something went wrong ... Please have a look at my logs. |
* MNT: Add a fused numeric type to make fused_types more constent. * MNT: make the interpolation use fused types for any->any type interpolation of images. * MNT: Move even more numpy function calls from Cython to Python. * MNT: More explicit type specifying * BUG: Use fused floats in denoise Pull all denoise array allocation out into python Function used in python should be def not cdef Have the correct number of arguments * MNT: Add additional type check for denoise, more docs * PEP8 fixes * Remove redundant array u and view cu * Mutate output array in Cython and trim in Python * Replace height and width with existing rows and cols * Change iteration order to match array order * Move range_lut and color_lut properly from Cy to Py * Ravel range LUT which is expected to be 1D * Update comment in denoise bilateral tests * Fix relative import in interpolation.pyx * BENCH: Benchmark for warping with many types * Rename warp benchmark file * Update pointer syntax Co-Authored-By: Mark Harfouche <mark.harfouche@gmail.com>
* Backport: use fused types in denoise, warp (#3486) * MNT: Add a fused numeric type to make fused_types more constent. * MNT: make the interpolation use fused types for any->any type interpolation of images. * MNT: Move even more numpy function calls from Cython to Python. * MNT: More explicit type specifying * BUG: Use fused floats in denoise Pull all denoise array allocation out into python Function used in python should be def not cdef Have the correct number of arguments * MNT: Add additional type check for denoise, more docs * PEP8 fixes * Remove redundant array u and view cu * Mutate output array in Cython and trim in Python * Replace height and width with existing rows and cols * Change iteration order to match array order * Move range_lut and color_lut properly from Cy to Py * Ravel range LUT which is expected to be 1D * Update comment in denoise bilateral tests * Fix relative import in interpolation.pyx * BENCH: Benchmark for warping with many types * Rename warp benchmark file * Update pointer syntax Co-Authored-By: Mark Harfouche <mark.harfouche@gmail.com> * forward port check_sdist
Description
Fixes #3449, #1287
Supersedes #3469, #3253 (I think), #1977.
All credit to @AetherUnbound and @hmaarrfk here, I have just rebased their work on the latest master after @hmaarrfk fixed our negative indexing use in Cython.
Checklist
Gallery example in./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x