Skip to content
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

[BUG] region_props handling of NumPy array #789

Open
JHancox opened this issue Oct 9, 2024 · 1 comment
Open

[BUG] region_props handling of NumPy array #789

JHancox opened this issue Oct 9, 2024 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@JHancox
Copy link

JHancox commented Oct 9, 2024

Describe the bug
In cucim.skimage.measure, region_props allows you to pass in a numpy object and some properties work okay (e.g. bbox) whereas others produce an error when evaluated (e.g. centroid). This inconsistency is somewhat confusing. It seems that ndarray is only partially supported internally.

Steps/Code to reproduce bug

import cupy as cp
from cucim.skimage import measure

a = np.array([[0,0,0,0,0,0,0],
              [0,1,1,1,0,0,0],
              [0,1,1,1,0,0,0],
              [0,1,1,1,0,0,0],
              [0,0,0,2,2,2,0],
              [0,0,0,2,2,0,0],
              [0,0,0,3,3,0,0]])

# Uncomment and it works. Omit this and some properties work 
# a = cp.array(a)

res = measure.regionprops(a)

for r in res:
    print(r.bbox, r.centroid)

Expected behavior
All properties should either work without error or should fail consistently

Environment details (please complete the following information):
Running Vista2D container, which includes cucim v23.12.1

Additional context

@JHancox JHancox added the bug Something isn't working label Oct 9, 2024
@jakirkham jakirkham changed the title [BUG] [BUG] region_props handling of NumPy array Oct 9, 2024
@grlee77
Copy link
Contributor

grlee77 commented Jan 14, 2025

Thanks for reporting the issue, @JHancox. I will work on a fix for this.

FYI, I am currently working on improving regionprops for GPU as I think it is a popular part of scikit-image, but is currently not accelerated well in cuCIM. I am not sure we can improve the case involving calling RegionProps on individual labels as in the code above, but my goal is to provide >10x improvement for properties computed via regionprops_table.

So for GPU use, once the revised implementation is available it should be much faster to do

props = measure.regionprops_table(a, properties=['bbox', 'centroid'])

than

res = measure.regionprops(a)

for r in res:
    print(r.bbox, r.centroid)

The later is problematic as individual regions are often small, so much of the GPU sits idle and there is separate kernel launch overhead for each region. We can avoid both of these issues when computing properties for all labels at once.

@grlee77 grlee77 added this to the v25.02.00 milestone Jan 14, 2025
@grlee77 grlee77 self-assigned this Jan 14, 2025
@grlee77 grlee77 added this to cucim Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

2 participants