ResizeMix¶
- class mmcls.models.utils.batch_augments.ResizeMix(alpha, lam_min=0.1, lam_max=0.8, interpolation='bilinear', cutmix_minmax=None, correct_lam=True)[source]¶
ResizeMix Random Paste layer for a batch of data.
The ResizeMix will resize an image to a small patch and paste it on another image. It’s proposed in ResizeMix: Mixing Data with Preserved Object Information and True Labels
- Parameters
alpha (float) – Parameters for Beta distribution to generate the mixing ratio. It should be a positive number. More details can be found in
Mixup
.lam_min (float) – The minimum value of lam. Defaults to 0.1.
lam_max (float) – The maximum value of lam. Defaults to 0.8.
interpolation (str) – algorithm used for upsampling: ‘nearest’ | ‘linear’ | ‘bilinear’ | ‘bicubic’ | ‘trilinear’ | ‘area’. Defaults to ‘bilinear’.
prob (float) – The probability to execute resizemix. It should be in range [0, 1]. Defaults to 1.0.
cutmix_minmax (List[float], optional) – The min/max area ratio of the patches. If not None, the bounding-box of patches is uniform sampled within this ratio range, and the
alpha
will be ignored. Otherwise, the bounding-box is generated according to thealpha
. Defaults to None.correct_lam (bool) – Whether to apply lambda correction when cutmix bbox clipped by image borders. Defaults to True
**kwargs – Any other parameters accpeted by
CutMix
.
Note
The \(\lambda\) (
lam
) is the mixing ratio. It’s a random variable which follows \(Beta(\alpha, \alpha)\) and is mapped to the range [lam_min
,lam_max
].\[\lambda = \frac{Beta(\alpha, \alpha)} {\lambda_{max} - \lambda_{min}} + \lambda_{min}\]And the resize ratio of source images is calculated by \(\lambda\):
\[\text{ratio} = \sqrt{1-\lambda}\]- mix(batch_inputs, batch_scores)[source]¶
Mix the batch inputs and batch one-hot format ground truth.
- Parameters
batch_inputs (Tensor) – A batch of images tensor in the shape of
(N, C, H, W)
.batch_scores (Tensor) – A batch of one-hot format labels in the shape of
(N, num_classes)
.
- Returns
The mixed inputs and labels.
- Return type
Tuple[Tensor, Tensor)