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

RandomWeightedCrop doesn't randomly generate crops for a weightmap of integers #7949

Closed
gregspangenberg opened this issue Jul 25, 2024 · 0 comments · Fixed by #8097
Closed
Labels
bug Something isn't working Contribution wanted good first issue Good for newcomers

Comments

@gregspangenberg
Copy link

Describe the bug
monai.transforms.RandomWeightedCrop uses the function monai.transforms.utils.weighted_patch_samples. At line 576 in utils the weighted_patch_samples function converts the datatype of the randomly generate number in the range of (0,1) to match the datatype of the input weightmap.
"""
r, *_ = convert_to_dst_type(r_state.random(n_samples), v)
"""
If the weightmap consisted of integers then the random value will always be the integer of 0, which disables random sampling and instead samples from the first valid region continuously.

To Reproduce
Steps to reproduce the behavior:

  1. Create a numpy weightmap with integer datatype
  2. Pass weightmap into RandomWeightedCrop
  3. Observe the "crop_center" value in the meta data of the cropped image after multiple iterations it will remain constant

Expected behavior
The random factor "r" should never be an converted to an integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Contribution wanted good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants