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

6699 random sort grid patch #6701

Merged
merged 19 commits into from
Jul 13, 2023
Merged

Conversation

jmnolte
Copy link
Contributor

@jmnolte jmnolte commented Jul 7, 2023

Description

The PR introduces a random sorting option to the GridPatch, RandGridPatch, GridPatchd, RandGridPatchd transforms. So far, the transforms allowed patches to be sorted according to the sum of their intensity or in their default order (i.e., sliding-window manner). With this PR, random extraction of patches as described in Myronenko et al. is enabled.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.

@KumoLiu KumoLiu requested review from wyli, drbeh and KumoLiu July 8, 2023 10:35
@KumoLiu KumoLiu requested a review from ericspod July 8, 2023 10:43
@jmnolte jmnolte marked this pull request as draft July 10, 2023 12:44
Copy link
Member

@drbeh drbeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmnolte Thanks for your contribution. The only downside of implementing the randomness is GridPatch is that this transform is supposed to be non-random while relying on its random counter part RandGridPatch to include randomness. Thus, I would suggest to only modify RandGridPatch for this purpose by overriding its filter_count method, handling situation with sort_fn="random", and delegating the rest to the its parent class.

def filter_count(self, image_np: NdarrayOrTensor, locations: np.ndarray) -> tuple[NdarrayOrTensor, np.ndarray]:
    if self.sort_fn == GridPatchSort.RANDOM:
        pass # do your logic for random sorting here
        return image_np, locations
    return super().filter_count(image_np, locations)

Copy link
Member

@drbeh drbeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it would be great if you can update docstring for RandGridPatchd (the dictionary version of the transform) for this new option ("random") too. Thanks

@jmnolte jmnolte marked this pull request as ready for review July 11, 2023 06:45
@jmnolte
Copy link
Contributor Author

jmnolte commented Jul 11, 2023

Thanks to everyone for the reviews. As per popular request from @wyli and @drbeh, I have now adapted the random sorting option to only be implemented in the class' randomised version RandGridPatch.

@jmnolte jmnolte marked this pull request as draft July 11, 2023 14:58
@jmnolte jmnolte marked this pull request as ready for review July 12, 2023 08:32
@jmnolte
Copy link
Contributor Author

jmnolte commented Jul 12, 2023

Thanks for the feedback! I have now created a new filter_count method in RandGridPatch that overrides the parent's method if sort_fn=random. Let me know what you think.

monai/transforms/spatial/array.py Outdated Show resolved Hide resolved
monai/transforms/spatial/array.py Outdated Show resolved Hide resolved
jmnolte and others added 2 commits July 12, 2023 14:00
Co-authored-by: YunLiu <[email protected]>
Signed-off-by: Jakob Nolte <[email protected]>
Co-authored-by: YunLiu <[email protected]>
Signed-off-by: Jakob Nolte <[email protected]>
Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, it looks good to me -- please help fix the typing error

Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick update, LGTM. Could you please help also update the docstring in the RandGridPatchd?

@jmnolte
Copy link
Contributor Author

jmnolte commented Jul 13, 2023

I am not quite sure, what's causing the typing error. It appears that the index is of an invalid type but I don't see how the index type returned from GridPatchSort.RANDOM is different from the type returned from the other sorting options. Could anyone take a look?

@wyli
Copy link
Contributor

wyli commented Jul 13, 2023

sure, I'll have a look and trigger more tests @jmnolte.

@wyli
Copy link
Contributor

wyli commented Jul 13, 2023

/build

@wyli wyli requested review from Nic-Ma and drbeh July 13, 2023 09:35
Copy link
Member

@drbeh drbeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the comments. LGTM!

@drbeh drbeh merged commit 9a30390 into Project-MONAI:dev Jul 13, 2023
32 checks passed
@jmnolte jmnolte deleted the 6699-random-sort-GridPatch branch July 13, 2023 15:21
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 this pull request may close these issues.

4 participants