New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLIC Error: ValueError: Buffer dtype mismatch, expected 'long' but got 'long long' #679

Closed
rexdouglass opened this Issue Aug 8, 2013 · 13 comments

Comments

Projects
None yet
5 participants
@rexdouglass

rexdouglass commented Aug 8, 2013

Short Version: SLIC worked fine on skimage 8.0, python-2.7.5, 64 bit, windows 7, installed from a binary.
Upgraded to Skimage dev yesterday, compiled from source with Microsoft Windows SDK for Windows 7.

SLIC now returns "ValueError: Buffer dtype mismatch, expected 'long' but got 'long long'"

I need dev skimage for other new functions, so is there a way to roll back just SLIC to 8.0 until this is fixed?

Example code

from skimage.data import lena
from skimage.segmentation import slic
img = img_as_float(lena()[::2, ::2])
segments_slic = slic(img, ratio=10, n_segments=250, sigma=1)

Traceback (most recent call last):

File "", line 13, in
segments_slic = slic(img, ratio=10, n_segments=250, sigma=1)

File "C:\WinPython-64bit-2.7.5.1b\python-2.7.5.amd64\lib\site-packages\scikit_image-0.9dev-py2.7-win-amd64.egg\skimage\segmentation\slic_superpixels.py", line 140, in slic
max_iter, n_segments)

File "_slic.pyx", line 17, in skimage.segmentation._slic._slic_cython (skimage\segmentation_slic.c:1947)

ValueError: Buffer dtype mismatch, expected 'long' but got 'long long'

In [24]: img = img_as_float(lena()[::2, ::2])
...: segments_slic = slic(img, ratio=10, n_segments=250, sigma=1)
Traceback (most recent call last):

File "", line 2, in
segments_slic = slic(img, ratio=10, n_segments=250, sigma=1)

File "C:\WinPython-64bit-2.7.5.1b\python-2.7.5.amd64\lib\site-packages\scikit_image-0.9dev-py2.7-win-amd64.egg\skimage\segmentation\slic_superpixels.py", line 140, in slic
max_iter, n_segments)

File "_slic.pyx", line 17, in skimage.segmentation._slic._slic_cython (skimage\segmentation_slic.c:1947)

ValueError: Buffer dtype mismatch, expected 'long' but got 'long long'

In [25]: from skimage.data import lena
...: from skimage.segmentation import slic
...: img = img_as_float(lena()[::2, ::2])
...: segments_slic = slic(img, ratio=10, n_segments=250, sigma=1)
Traceback (most recent call last):

File "", line 4, in
segments_slic = slic(img, ratio=10, n_segments=250, sigma=1)

File "C:\WinPython-64bit-2.7.5.1b\python-2.7.5.amd64\lib\site-packages\scikit_image-0.9dev-py2.7-win-amd64.egg\skimage\segmentation\slic_superpixels.py", line 140, in slic
max_iter, n_segments)

File "_slic.pyx", line 17, in skimage.segmentation._slic._slic_cython (skimage\segmentation_slic.c:1947)

ValueError: Buffer dtype mismatch, expected 'long' but got 'long long'

@JDWarner

This comment has been minimized.

Contributor

JDWarner commented Aug 8, 2013

This example runs fine on Linux, except for an expected warning to use compactness kwarg instead of ratio in the future. Seems like a problem particular to Windows, but I can't track it further.

@jni

This comment has been minimized.

Contributor

jni commented Aug 8, 2013

Well, the only long buffer expected by _slic_cython is nearest_mean, which is declared as dtype=np.intp (in skimage/segmentation/slic_superpixels.py, line 137). I guess that resolves to long in *Nix (this example also works fine in OSX), but long long in Windows. @rexdouglass, if you change that array declaration to dtype=long, it should work!

@JDWarner @stefanv , any reason why that shouldn't be changed for master also? I just tested it and it works fine, I've just never seen a numpy array declared as long. Or should I change the buffer type to np.intp instead? It's been quite a while since I've thought hard about cross-platform type safety. ;)

@ahojnnes

This comment has been minimized.

Member

ahojnnes commented Aug 9, 2013

@jni It should work cross-platform if you declare the Cython array as cnp.intp_t or Py_ssize_t, which I would also recommend for max_iter and num_segments.

@jni

This comment has been minimized.

Contributor

jni commented Aug 9, 2013

@ahojnnes, are they synonyms? Is there any reason to pick one over the other? And will they both resolve correctly from coming from ints in Python?

@stefanv

This comment has been minimized.

Member

stefanv commented Aug 9, 2013

I thought we updated the developer guide with some hints on this, but if
not I'll gladly do so.

@jni

This comment has been minimized.

Contributor

jni commented Aug 9, 2013

Right you are, @stefanv! It's at the bottom of the stylistic guidelines. Missed that one, and anyway wouldn't have been sure if it applied to memoryviews. =) Fix forthcoming!

@jni

This comment has been minimized.

Contributor

jni commented Aug 9, 2013

In the docstring, should I write "int", "integer", something else...?

@ahojnnes

This comment has been minimized.

Member

ahojnnes commented Aug 9, 2013

I think, we typically stick with "int".

@JDWarner

This comment has been minimized.

Contributor

JDWarner commented Aug 10, 2013

@rexdouglass Please pull the latest upstream and test; hopefully #682 resolved this issue.

@jni

This comment has been minimized.

Contributor

jni commented Aug 25, 2013

@rexdouglass , can you confirm that this issue is resolved?

@rexdouglass

This comment has been minimized.

rexdouglass commented Aug 25, 2013

Unfortunately I'm in the middle of a move and will be apart from my
hardware until Sept. Will resume my project and can verify this ASAP.

On Sun, Aug 25, 2013 at 4:07 AM, Juan Nunez-Iglesias <
notifications@github.com> wrote:

@rexdouglass https://github.com/rexdouglass , can you confirm that this
issue is resolved?


Reply to this email directly or view it on GitHubhttps://github.com//issues/679#issuecomment-23225773
.

Rex W. Douglass
Postdoctoral Research Associate
Institute on Global Conflict and Cooperation (IGCC);
Department of Mathematics
University of California, San Diego
512.791.5202
rexdouglass.com

@stefanv

This comment has been minimized.

Member

stefanv commented Aug 26, 2013

Thanks, @rexdouglass. I'm going to close this in the mean time, but feel free to re-open should the issue come up again.

@stefanv stefanv closed this Aug 26, 2013

@rexdouglass

This comment has been minimized.

rexdouglass commented Aug 26, 2013

Thanks very much for the help.

On Sun, Aug 25, 2013 at 11:52 PM, Stefan van der Walt <
notifications@github.com> wrote:

Thanks, @rexdouglass https://github.com/rexdouglass. I'm going to close
this in the mean time, but feel free to re-open should the issue come up
again.


Reply to this email directly or view it on GitHubhttps://github.com//issues/679#issuecomment-23246280
.

Rex W. Douglass
Postdoctoral Research Associate
Institute on Global Conflict and Cooperation (IGCC);
Department of Mathematics
University of California, San Diego
512.791.5202
rexdouglass.com

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