Add batch-wise random erasing support?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
🚀 Feature
Motivation
The random erasing supported in torchvision now is implemented as image-wise. I need to use it after data loader collecting batches. But the current design cannot be used for a large batch because it is too slow to preprocess on CPU.
I use a for loop to process per-image in a batch, as shown below, but it is too slow:
for batch_of_imgs, labels in my_data_loader:
# I need apply random erasing here, not in transforms of data loader
# This for-loop is too slow!!!
for i, img in enumerate(batch_of_imgs):
batch_of_imgs[i] = RandomErasing(img)
# train model as usual
preds = model(batch_of_imgs, labels)
Pitch
If a batch-wise random erasing operation that could accelerate such preprocessing is available, it would be very helpful.
Alternatives
I've tried 2 alternatives:
- Use multi-threading. This does not help due to python GIL.
- Use multi-processing. This saves around 50% preprocessing time per-iteration at the beginning of training but gradually becomes as slow as single-processing one. It provides around <10% improvements from the whole training procedure but requires more resources for processing management, and tricky hacks to modify training code.
Additional context
The erasing procedure should be image-wise, not batch-wise. In other words, the erased region cannot be shared among images of same batch.
cc @SsnL @VitalyFedyunin @ejguan @fmassa @vfdev-5
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 locating torchvision's existing RandomErasing implementation and its related tests. Define a batch-capable interface that keeps erased regions independent per image, then benchmark it against the reported per-image loop and add coverage for the batch behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100