-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add AsContiguous utility transform #3610
Description
Is your feature request related to a problem? Please describe.
Our internal QA team reported a performance issue that:
Running exact same spleen segmentation program on MONAI 0.7+ is 50% slower than on MONAI 0.5.3, in the same PyTorch 21.10 docker.
Then @yiheng-wang-nv and I spent much time to investigate the issue, finally, I found that in the new code, we can skip the padding if not necessary:
https://github.com/Project-MONAI/MONAI/blob/dev/monai/transforms/croppad/array.py#L128
While in the 0.5.3 code, it always pad the array.
And this pad API will potentially convert a non-contiguous NumPy array to a contiguous array, which will make the following transforms much faster when running with 0.5.3.
I think we faced several times contiguous related issues or discussions, would be nice to add an AsContiguous transform for both NumPy array and PyTorch Tensor. Then users can explicitly add this transform to whatever place of the transform chain.
It would be obviously useful to convert to contiguous before CacheDataset caching.
@ericspod @wyli @rijobro What do you guys think?