Shortcuts

ClsDataPreprocessor

class mmpretrain.models.utils.data_preprocessor.ClsDataPreprocessor(mean=None, std=None, pad_size_divisor=1, pad_value=0, to_rgb=False, to_onehot=False, num_classes=None, batch_augments=None)[源代码]

用于分类任务的图像预处理器

Comparing with the mmengine.model.ImgDataPreprocessor,

  1. It won’t do normalization if mean is not specified.

  2. It does normalization and color space conversion after stacking batch.

  3. It supports batch augmentations like mixup and cutmix.

It provides the data pre-processing as follows

  • Collate and move data to the target device.

  • Pad inputs to the maximum size of current batch with defined pad_value. The padding size can be divisible by a defined pad_size_divisor

  • Stack inputs to batch_inputs.

  • 如果输入的 tensor 形状为 (3, H, W),则可以执行 BGR 到 RGB 的通道转换

  • 根据给定的均值和方差对图像进行归一化

  • Do batch augmentations like Mixup and Cutmix during training.

参数:
  • mean (Sequence[Number], optional) – The pixel mean of R, G, B channels. Defaults to None.

  • std (Sequence[Number], optional) – The pixel standard deviation of R, G, B channels. Defaults to None.

  • pad_size_divisor (int) – The size of padded image should be divisible by pad_size_divisor. Defaults to 1.

  • pad_value (Number) – The padded pixel value. Defaults to 0.

  • to_rgb (bool) – whether to convert image from BGR to RGB. Defaults to False.

  • to_onehot (bool) – Whether to generate one-hot format gt-labels and set to data samples. Defaults to False.

  • num_classes (int, optional) – The number of classes. Defaults to None.

  • batch_augments (dict, optional) – The batch augmentations settings, including “augments” and “probs”. For more details, see mmpretrain.models.RandomBatchAugment.

forward(data, training=False)[源代码]

Perform normalization, padding, bgr2rgb conversion and batch augmentation based on BaseDataPreprocessor.

参数:
  • data (dict) – data sampled from dataloader.

  • training (bool) – Whether to enable training time augmentation.

返回:

Data in the same format as the model input.

返回类型:

dict

Read the Docs v: latest
Versions
latest
stable
mmcls-1.x
mmcls-0.x
dev
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.