Shortcuts

ImgDataPreprocessor

class mmengine.model.ImgDataPreprocessor(mean=None, std=None, pad_size_divisor=1, pad_value=0, bgr_to_rgb=False, rgb_to_bgr=False, non_blocking=False)[source]

Image pre-processor for normalization and bgr to rgb conversion.

Accepts the data sampled by the dataloader, and preprocesses it into the format of the model input. ImgDataPreprocessor provides the basic data pre-processing as follows

  • Collates and moves data to the target device.

  • Converts inputs from bgr to rgb if the shape of input is (3, H, W).

  • Normalizes image with defined std and mean.

  • Pads 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.

For ImgDataPreprocessor, the dimension of the single inputs must be (3, H, W).

Note

ImgDataPreprocessor and its subclass is built in the constructor of BaseDataset.

Parameters:
  • mean (Sequence[float or int], optional) – The pixel mean of image channels. If bgr_to_rgb=True it means the mean value of R, G, B channels. If the length of mean is 1, it means all channels have the same mean value, or the input is a gray image. If it is not specified, images will not be normalized. Defaults None.

  • std (Sequence[float or int], optional) – The pixel standard deviation of image channels. If bgr_to_rgb=True it means the standard deviation of R, G, B channels. If the length of std is 1, it means all channels have the same standard deviation, or the input is a gray image. If it is not specified, images will not be normalized. Defaults None.

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

  • pad_value (float or int) – The padded pixel value. Defaults to 0.

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

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

  • non_blocking (bool) – Whether block current process when transferring data to device. New in version v0.3.0.

Note

if images do not need to be normalized, std and mean should be both set to None, otherwise both of them should be set to a tuple of corresponding values.

forward(data, training=False)[source]

Performs normalization, padding and bgr2rgb conversion based on BaseDataPreprocessor.

Parameters:
  • data (dict) – Data sampled from dataset. If the collate function of DataLoader is pseudo_collate, data will be a list of dict. If collate function is default_collate, data will be a tuple with batch input tensor and list of data samples.

  • training (bool) – Whether to enable training time augmentation. If subclasses override this method, they can perform different preprocessing strategies for training and testing based on the value of training.

Returns:

Data in the same format as the model input.

Return type:

dict or list

Read the Docs v: latest
Versions
latest
stable
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.1
v0.9.0
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.