[WIP] Add fused types, attempt to use in denoise#3469
[WIP] Add fused types, attempt to use in denoise#3469AetherUnbound wants to merge 6 commits intoscikit-image:masterfrom
Conversation
|
Let me cleanup that PR. you should be able to cherry-pick the commits really soon and incldue them in your PR. |
|
@AetherUnbound Feel free to just cherry pick the commits you need from my fork. I tested the interpolation fused code with the test suite so hopefully it shouldn't cause you lots of problems. No guarantees that it will work, but you know, if it helps. you might also want to have a look at this PR: #3254 |
|
@AetherUnbound good stuff! I think the best approach now is:
Let us know if you need any git-help! |
|
Looking at his profile, I'm pretty sure @AetherUnbound knows how to use git but he was just being polite 😅 didn't mean to insult. |
|
Oh no I didn't take it that way at all! Haha cherry picking is actually not something I've done before so it'll be a nice experiment for me 😉 |
2231386 to
4dabf7f
Compare
|
Thanks for all the help/suggestions guys - I've cherry-picked the commits but now when I try to run I'm assuming this has to do with the md5/c compiled stuff. |
|
I've changed Even after doing a |
|
Can you try to remove all md5 files and compile again with python setup develop or pip install. You have to keep running those commands every change |
|
I ran the following and am still getting the same issue with the |
skimage/restoration/_denoise_cy.pyx
Outdated
|
|
||
| cdef: | ||
| double[:] color_lut = np.empty(bins, dtype=np.double) | ||
| np_floats[:] color_lut = np.empty(bins, dtype=np.double) |
There was a problem hiding this comment.
right hand side should probably be np_floats as well.
There was a problem hiding this comment.
Your choice, but I would just pop out this numpy array creation out of cython. It doesn't save much time and is annoying to write in cython. But do what you want.
There was a problem hiding this comment.
Looking at this at a reasonable type, I can see why this is done in cython, these seem like implementation details of the algorithm. I think you might just need to change np.double to np_floats. For each version of the function, Cython will pick the same float for all instances of np_floats in a function.
skimage/restoration/_denoise_cy.pyx
Outdated
|
|
||
| cdef: | ||
| double[:] range_lut = np.empty(win_size*win_size, dtype=np.double) | ||
| np_floats[:] range_lut = np.empty(win_size*win_size, dtype=np.double) |
skimage/restoration/_denoise_cy.pyx
Outdated
| double[:, :, ::1] bx = np.zeros(shape_ext, dtype=np.double) | ||
| double[:, :, ::1] by = np.zeros(shape_ext, dtype=np.double) | ||
| np_floats[:, :, ::1] dx = np.zeros(shape_ext, dtype=np.double) | ||
| np_floats[:, :, ::1] dy = np.zeros(shape_ext, dtype=np.double) |
|
FYI, that MD5 PR just got pulled in. If you want you can pull upstream mster, and rebase your branch. |
926b499 to
ae21ab6
Compare
|
Awesome, I've rebased and changed |
|
Rightttttt so that was the real reason why I recommended against using where by I had different branches for each type I wanted to support. I just don't think it is possible to do this without this kind of hack. For me, it was only used for the output array of warp. Therefore, I moved that to python, and didn't deal with it again. For you, depending on if you think it be best to continue this in Cython, it might look something like: |
|
Thanks @hmaarrfk! I'm not sure how I'd refactor denoise to pull out all of the I've given it a stab in cython: But I'm getting the following errors: (Sorry I'm not of more help here 😭) |
|
Dtype is a real hack. You should basically pass sigma in. |
|
Got it, I'm passing in And an example call: And the compiler error: This make me believe that I don't have the types defined in the inline function correctly, but it works for the |
|
Got it - I totally missed that |
|
Turns out I wasn't close at all (cause I was checking if the parameter passed in was With error: |
|
I'm going to go ahead and second @hmaarrfk's original sentiment that you should aim to make all allocations in Python and then pass both input and output arrays to Cython. That will greatly simplify the code, as maintaining input dtypes in Python is super easy: |
|
And of course there is virtually zero performance benefit in doing this in Cython. |
|
I like that idea! The trouble is that there's all these other arrays that should also be zero (https://github.com/scikit-image/scikit-image/blob/master/skimage/restoration/_denoise_cy.pyx#L116-L122), but this is all done with shape calculations based on the |
|
@AetherUnbound yes, feel free to “refactor with abandon”, as a friend once put it. That’s what the tests are for! =) (And of course, at the end of it, please add a test with a float32 image as input!) |
|
🎉 this is all super-awesome! However, we have an ominous looking error in AppVeyor: https://ci.appveyor.com/project/scikit-image/scikit-image/builds/19505999/job/549juoaxo0lgn1mt#L8039 |
|
Or you can ignore me if that last commit fixes it. =P |
|
@jni it likely doesn't and I don't know why that error is occurring :< |
|
Ouch. This seems to suggest that we need to acquire the GIL for some of the code: Just to double check: tests run fine on your machine? |
|
I take it back: the comments under the selected answer suggest that the answer made things worse! Why is the answer ticked??? 😂 |
|
Yea, they do work on my machine! |
|
This other thread suggests that the error code means "memory corruption", which indeed sounds so ominous! Gah! Anyway let me play around with it... Thank you very much for your efforts! |
|
Okay, let me know if there's anything else I can do - thanks! |
|
|
||
| shape_ext = (rows2, cols2, dims) | ||
| u = np.zeros(shape_ext, dtype=np.double) | ||
| u = out.copy() |
There was a problem hiding this comment.
you should explain what this is. Can you call np.zeros_like instead?
There was a problem hiding this comment.
I can definitely add a comment here
|
This kinda seems silly: The |
We can't have negative indices. |
|
Nevermind, I don't like |
The operational stuff in this isn't my code - what would you suggest here? |
|
Fix it, keep it as a seperate commit if you wish for you PR not to be squashed. If @jni wants, we can think of making a seperate PR, but maybe this is ok to bundle? |
|
What I mean to say is, how would I change this to not use negative indices? And why are negative indices bad in the first place? 😮 |
disables negative indices in cython. might work |
|
Hooray for platform-specific failures! ~/projects/scikit-image (bugfix/float-cast)
$ pytest skimage/restoration/tests/test_denoise.py
==================================================== test session starts =====================================================
platform linux -- Python 3.6.3, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /home/jni/projects/scikit-image/skimage/restoration, inifile:
plugins: cov-2.5.1, hypothesis-3.56.9
collected 39 items
skimage/restoration/tests/test_denoise.py ........F.............................. [100%]
========================================================== FAILURES ==========================================================
_________________________________________ test_denoise_tv_bregman_float_result_range _________________________________________
def test_denoise_tv_bregman_float_result_range():
# astronaut image
img = astro_gray.copy()
int_astro = np.multiply(img, 255).astype(np.uint8)
assert_(np.max(int_astro) > 1)
denoised_int_astro = restoration.denoise_tv_bregman(int_astro, weight=60.0)
# test if the value range of output float data is within [0.0:1.0]
assert_(denoised_int_astro.dtype == np.float)
> assert_(np.max(denoised_int_astro) <= 1.0)
E AssertionError
skimage/restoration/tests/test_denoise.py:152: AssertionError
============================================ 1 failed, 38 passed in 5.10 seconds =============================================sigh, gonna head to bed now, I'll try to figure it out tomorrow. |
|
@jni that's so weird because I'm running very similar versions on linux and it was working O_o |
|
I really think this is the negative indexing guys. Your basically using memory your not supposed to. |
|
Okay @hmaarrfk, I'll try to address that today! |
|
I was just saying that it seems more like a memory out of bounds problem, than a OS Specific one seeing that we found a place where negative indices were used. Sometimes, the order in which memory is allocated causes these problems to pop up. Finally, using different OSs makes use of different memory allocators as well, which also causes these problems to surface occasionally. We've been able to use 32bit linux builds to spot a few other problems in Cython, mostly related to using int64/int32 as pointers when we weren't supposed to. |
|
@hmaarrfk 🤦♂️ Ok but I still see @AetherUnbound's point: as far as I can tell, the diff doesn't touch the Cython wraparound call or the negative indexing, so why was it working before. Was it working before?? Also, should we just create |
|
np pad PR is held up.
Basically, there is a trade off between high level python and straight
concatenation because it is implemented in C.
I wouldn’t use pad or block for these well posed problems.
…On Mon, Oct 15, 2018 at 8:00 PM Juan Nunez-Iglesias < ***@***.***> wrote:
@hmaarrfk <https://github.com/hmaarrfk> 🤦♂️
Ok but I still see @AetherUnbound <https://github.com/AetherUnbound>'s
point: as far as I can tell, the diff doesn't touch the Cython wraparound
call or the negative indexing, so why was it working before. *Was it*
working before??
Also, should we just create u in Python with np.pad?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3469 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFfmBMALj-BIss0zsuVjA95x6FCFp_Vks5ulSGlgaJpZM4XX75i>
.
|
|
Might be relevant to the negative index bug: cython/cython#2539 |
|
@AetherUnbound I think you should just continue your work on this PR. It seems that the intermittent failer was caused because the In finding that bug, it went through the code again and a few places that could be cleaned up:
|
|
Sorry I've let this sit for so long! I want to jump back in but it looks like there's some conflicts, @hmaarrfk any advice on how to resolve them? |
|
Closing in favour of #3486 |
Description
This is my first stab at adding the fused types from #3253 in order to fix the issue identified in #3449. I'm totally new to Cython as a whole, so I'm open to assistance with this one!
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
(Don't remove the checklist below.)
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x