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.
allow_negative_crop takes a bool or float as argument.
When allow_negative_crop is False (either defined as False in the argument or set to False by probability in the code) margin intervals likely to contain instance(s) with the desired min_overlap (IoF) are calculated and randomly sampled from.
The resulting crop window is compared by IoF with the bboxes in a loop
If no foreground is found the method returns None as before
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.