Project-MONAI / Project-MONAI/MONAI
Patch dataset seems extremely inefficient in training
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.7k
- Forks
- 1.6k
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 20
Description
Hello! Thank you for this incredible library! I'm loving my experience with MONAI so far.
Is your feature request related to a problem? Please describe.
But I've noticed a severe inefficiency in the way PatchDataset is written. If used with RandSpacialCropSamplesd, as it is in the example, it takes more time to sample the same number of patches, than if using RandSpacialCropd with a simple Dataset. That's due to how the patches are sampled: for every patch, first, all patches are resampled, then a patch is chosen with the corresponding index, while the other sampled patches are just thrown away. So, this creates two problems
- First, obviously, it is unnecessarily slow, re-sampling patches every time, so it makes no sense to use it to speed up training.
- Second, it eats up more memory than it should. One could easily implement this with generators, so that the memory footprint would be basically the same as in sampling a single patch.
Describe the solution you'd like
I wish PatchDataset would store a generator inside, which would yield patches. On StopIteration, one would store newly-sampled patches in the generator. Also, please add a flag, allowing to turn RandSpacialCropSamplesd into a generator, so that it wouldn't store all sampled patches in memory. It would be slower than storing all of them in memory, but it would greatly reduce the memory footprint (to the footprint of sampling a single patch).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the PatchDataset and RandSpacialCropSamplesd implementations and the example that uses them. Compare how patches are sampled and retained, then define completion as avoiding unnecessary resampling and reducing memory use while preserving the requested patch output and existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100