open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.61k stars 9.47k forks source link

Minimum IoF overlap in RandomCrop Transform #8149

Open PeterVennerstrom opened 2 years ago

PeterVennerstrom commented 2 years ago

Usecase: support fine control over foreground/background training samples with RandomCrop

When allow_negative_crop == False current behavior returns None when the random crop location does not contain bbox foreground. This can result in many images being skipped when foreground is sparse and image sizes are large relative to the crop size e.g. when training models for sliding window inference. Skipping images adds unintended sampling bias towards images with more foreground coverage. It is also time consuming to load the next image when one is skipped.

It isn't currently possible to use RandomCrop to allow_negative_crop by a probability to enable the model to learn from a balanced sampling of background.

MinIoURandomCrop gives fine control over sampling foreground/background by setting min_ious to replicate a probability of foreground/background. MinIoURandomCrop does not support different crop types like: 'relative_range', 'relative', 'absolute', 'absolute_range'. MinIoURandomCrop uses IoU a box center point check rather than IoF. IoF has the benefit of putting the overlap calculation in terms of the foreground e.g. an image with a minimum .5 IoF threshold will contain an instance with at least half its area within the crop.

If the maintainers have an interest in supporting this functionality in RandomCrop I have an implementation for a PR.

The relevant code is here.

hhaAndroid commented 2 years ago

@PeterVennerstrom Thanks a lot for your feedback. we will think carefully.