Open
Conversation
benjijamorris
suggested changes
May 23, 2025
Contributor
benjijamorris
left a comment
There was a problem hiding this comment.
Looks great! My one suggestion would be to add an explicit spatial_dims argument. I think this would take the guesswork out of trying to find the spatial dimensions and make the code simpler but I can be convinced otherwise!
| raise TypeError(f"Input '{key}' must be a PyTorch tensor, got {type(x)}") | ||
|
|
||
| # Determine expected tensor dimensions and spatial size length | ||
| input_dims = x.dim() |
Contributor
There was a problem hiding this comment.
Monai transforms expect C[Z]YX images - would it be reasonable to enforce this based on the spatial size and then just add the batch dimension right before pooling? I often have an explicit spatial_dims argument to help with this kind of check
|
|
||
| # Normalize spatial_size to match expected number of spatial dimensions | ||
| try: | ||
| spatial_size = ensure_tuple_rep(self.spatial_size, expected_spatial_dims) |
Contributor
There was a problem hiding this comment.
Adding an explicit spatial_dims argument here would let you find the spatial size once in the init
|
|
||
| orig_size = x.shape[-expected_spatial_dims:] | ||
|
|
||
| # Replace non-positive spatial_size values with original dimensions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
maxpool_resizetransform to obtain maxpool-like functionality when resizing inputs.MONAI provides resize functionality via
monai.transforms.Resizedwhich usestorch.nn.functional.interpolatealong with one of the available interpolation modes. None of the modes offer the maxpool-like functionality and thus we need a custom transform. No additional dependencies required. This is an optional transform to be used with config and does not introduce any breaking changes.Before submitting
pytestcommand?pre-commit run -acommand?Did you have fun?
Make sure you had fun coding 🙃