question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `AsContiguous` utility transform

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Nic-Macommented, Jan 8, 2022

Hi @wyli ,

I submitted PR https://github.com/Project-MONAI/MONAI/pull/3614 to optionally support contiguous in CacheDataset. Verified with the training performance of spleen segmentation pipeline.

Thanks.

1reaction
Nic-Macommented, Jan 8, 2022

thanks, in this case what were the slow transforms when the memory is not contiguous?

Hi @wyli ,

In the spleen training pipeline, when the cached image, label is not contiguous, the RandCropByPosNegLabeld transform will be slower, because the numpy computation is much slower(5x slower) here: https://github.com/Project-MONAI/MONAI/blob/dev/monai/transforms/utils.py#L300 I verified that on local machine, @yiheng-wang-nv will help double confirm on other machines soon. Then I will try to implement the AsContiguous transform in our next v0.8.1rc3 tag if you guys don’t other concerns.

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cython for NumPy users
Cython is a compiler which compiles Python-like code files to C code. Still, ''Cython is not a Python to C translator''. That is,...
Read more >
numpy.ascontiguousarray — NumPy v1.24 Manual
Convert input to an ndarray with column-major memory order. require. Return an ndarray that satisfies requirements. ndarray.flags.
Read more >
Customize the reference grid—ArcGIS Pro | Documentation
Edit utility networks. Utility network reference for editing View ... Display the grid as contiguous lines or as grid points at all intersections....
Read more >
Marking Menus | Maya 2018 - Autodesk Knowledge Network
Common Transform marking menus. The following marking menus are common to the Select Tool, Move Tool, Rotate Tool, and Scale Tool.
Read more >
Create frame animations in Photoshop - Adobe Support
Add a layer or convert the background layer. ... these frames are treated as contiguous, and tweened frames are added after the last...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found