Skip to content

Denoise throws ValueError #3449

Description

@AetherUnbound

Description

_denoise_cy.pyx throws a ValueError saying a double was expected but a float was received.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aether/programs/anaconda3/envs/cellprofiler/lib/python2.7/site-packages/skimage/restoration/_denoise.py", line 117, in denoise_bilateral
    bins, mode, cval)
  File "skimage/restoration/_denoise_cy.pyx", line 114, in skimage.restoration._denoise_cy._denoise_bilateral
ValueError: Buffer dtype mismatch, expected 'double' but got 'float'

Way to reproduce

  • Code example
import numpy as np
import skimage.restoration

sigma = 16.0
sigma_range = .2
np.random.seed(0)
image = np.random.uniform(size=(100, 100)).astype(np.float32)
mask = np.ones(image.shape, bool)
mask[40:60, 45:65] = False
expected = skimage.restoration.denoise_bilateral(
    image=image,
    multichannel=False,
    sigma_color=sigma_range,
    sigma_spatial=sigma,
)
  • Relevant images (if any)
  • Operating system and version: Ubuntu 16.04
  • Python version
>>> print(sys.version)
2.7.14 |Anaconda, Inc.| (default, Dec  7 2017, 17:05:42) 
[GCC 7.2.0]
  • scikit-image version (run skimage.__version__)
>>> skimage.__version__
'0.14.1'

Activity

  1. jni commented on Oct 8, 2018

    @jni
    Member

    Holy moly! I believe #3110 introduced this: before, we would have upconverted your array to float64.

    @hmaarrfk added some nice fused typedefs in #3253. We should fast-track that so that we can use Cython fused types for float everywhere doubles are used currently — including in denoise_bilateral.

  2. hmaarrfk commented on Oct 8, 2018

    @hmaarrfk
    Member

    @jni, I think you should just pull out the relevant file. I'll deal with the conflicts later. (whoever works on this should pull out the relevant file)

  3. added
    ⚠️ Priority
    on Oct 8, 2018
  4. MaximLippeveld commented on May 24, 2019

    @MaximLippeveld

    I just compiled scikit-image 0.14.3 from source, which was supposed to fix this issue. Unfortunately, the issue remains in CellProfiler testing (see CellProfiler/CellProfiler#3661 (comment)).

    I get this error log:

        def test_05_01_bilateral(self):
            '''test the smooth module with bilateral filtering'''
            sigma = 16.0
            sigma_range = .2
            np.random.seed(0)
            image = np.random.uniform(size=(100, 100)).astype(np.float32)
            mask = np.ones(image.shape, bool)
            mask[40:60, 45:65] = False
            expected = skimage.restoration.denoise_bilateral(
                image=image,
                multichannel=False,
                sigma_color=sigma_range,
    >           sigma_spatial=sigma,
            )
    
    tests/modules/test_smooth.py:232: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    ../../../miniconda3/envs/cp-wxpython4-py2714/lib/python2.7/site-packages/skimage/restoration/_denoise.py:171: in denoise_bilateral
        range_lut, empty_dims, out)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    >   ???
    E   ValueError: Buffer dtype mismatch, expected 'float32_t' but got 'double'
    
    skimage/restoration/_denoise_cy.pyx:64: ValueError
    
  5. hmaarrfk commented on May 24, 2019

    @hmaarrfk
    Member

    Well well, we still haven't really released 0.14.3, maybe we can skip it and go straight to 0.14.4 ;) I'll look into it this weekend.

  6. jni commented on May 25, 2019

    @jni
    Member

    😭

  7. jni commented on May 25, 2019

    @jni
    Member

    Ummmmmm...

    This might be why we missed this:

    @pytest.mark.parametrize('dtype', [np.float16, np.float32, np.double])
    def test_denoise_bilateral_types(dtype):
    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)
    # check that we can process multiple float types
    out = restoration.denoise_bilateral(img, sigma_color=0.1,
    sigma_spatial=10, multichannel=False)

    tldr we parametrize the test on image dtype but then we don't actually use the dtype parameter 🤦‍♂️

  8. AetherUnbound commented on May 25, 2019

    @AetherUnbound
    Author

    Ah, that's almost certainly my fault D:

  9. jni commented on May 25, 2019

    @jni
    Member

    @AetherUnbound many eyeballs looked over that code and thought, "looks about right!" 😂

    I think the problem is that we overly constrain the other arguments to be np_floats — we should use regular double there and cast inside the function. I think. Don't have time to follow up right now. =\ Anyway, I'm going to reopen. 😞

  10. reopened this on May 25, 2019
  11. hmaarrfk commented on May 25, 2019

    @hmaarrfk
    Member

    I don't think there is fault so much as oops

  12. AetherUnbound commented on May 25, 2019

    @AetherUnbound
    Author

    Turns out my first forray into cython is not without Oops 😅

  13. bethac07 commented on Sep 3, 2019

    @bethac07

    Still getting this in 0.14.3 . Do we expect it to be fixed, or will that be in a later release?

  14. hmaarrfk commented on Sep 3, 2019

    @hmaarrfk
    Member

    Unfortunately, I think we missed it by a day, so we need to release 0.14.4 to get the fix in.

    I think this might be a good enough reason to release 0.14.4, but I personally don't have time for it right at this second. Maybe somebody else from @scikit-image/core has the time

    The PR that actually fixed things got in on May 28th
    #3936

    But the 0.14.3 tag was made a few days earlier.

  15. modified the milestones: 0.14.4, on Sep 3, 2019
  16. bethac07 commented on Sep 3, 2019

    @bethac07

    Thanks for letting me know! We're going to build/release the last CellProfiler release in the 3.X series in the next couple days, just need to figure out what skimage version to build it with. I appreciate the explanation, makes total sense!

  17. hmaarrfk commented on Sep 3, 2019

    @hmaarrfk
    Member

    FWIW, we did discuss skipping 0.14.3 alltogether and just release 0.14.4, but it ended up being quite hard to rally enough core devs behind the idea and get it right. I was waiting to hear back of a few more issues before release 0.14.4, but this seems like it is the main one, and should get addressed.

  18. jni commented on Sep 4, 2019

    @jni
    Member

    I've started the release process. 0.14.4 is tagged, wheels are building here:

    https://travis-ci.org/scikit-image/scikit-image-wheels/builds/580668076

    and here:

    https://ci.appveyor.com/project/scikit-image/scikit-image-wheels
    .

    Once they build I should be able to push to PyPI. But there are often issues with the wheel building, so we'll see. =\

  19. stefanv commented on Sep 4, 2019

    @stefanv
    Member

    Nice work! Linux + Mac wheels look good. For Windows, did it build the wrong tag? The error message looks suspicious:

    https://ci.appveyor.com/project/scikit-image/scikit-image-wheels/build/job/qmurjrlss2s6jfcd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ⚠️ Priority

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions