Skip to content

Allow processing data directly from cupy input. #17

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

Closed
jcfaracco opened this issue Jun 13, 2022 · 2 comments · Fixed by #18
Closed

Allow processing data directly from cupy input. #17

jcfaracco opened this issue Jun 13, 2022 · 2 comments · Fixed by #18

Comments

@jcfaracco
Copy link
Contributor

The example bellow does not work because it expects a numpy data from input. The code should also consider cupy data. Specially for workflows that are handling data directly from GPU.

import cupy as cp
from PIL import Image

# Here, we load in the array
# We divide the image by / 16 as it'll take too long

ar = cp.asarray(Image.open("../../data/image.jpg"))[::4,::4]

# We may use the class variant to run GLCM
from glcm_cupy import GLCM, Direction

g = GLCM(
    directions=(Direction.EAST, Direction.SOUTH_EAST),
    bin_from=256, bin_to=16).run(ar)

# Alternatively, use the function variant
from glcm_cupy import glcm

g = glcm(ar, bin_from=256, bin_to=16)

# We yield the features using constants defined in conf
from glcm_cupy.conf import CONTRAST, CORRELATION, ASM

print(g[..., CONTRAST])
print(g[..., CORRELATION])
print(g[..., ASM])

# Alternatively, since these constants are simply integers
print(g[..., 0])
print(g[..., 1])
print(g[..., 2])

It returns basically a TypeError:

TypeError: `arr_in` must be a numpy ndarray
@Eve-ning
Copy link
Owner

I see, should be a quick fix, I'll get to it this weekend

@jcfaracco
Copy link
Contributor Author

Thanks @Eve-ning . I appreciate your help. I would not like to submit a PR because you can decide how you could implement this. If you need any help. Just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants