Shortcuts

mmedit.models.data_preprocessors.gen_preprocessor

Module Contents

Classes

GenDataPreprocessor

Image pre-processor for generative models. This class provide

Attributes

CastData

mmedit.models.data_preprocessors.gen_preprocessor.CastData[source]
class mmedit.models.data_preprocessors.gen_preprocessor.GenDataPreprocessor(mean: Sequence[Union[float, int]] = (127.5, 127.5, 127.5), std: Sequence[Union[float, int]] = (127.5, 127.5, 127.5), pad_size_divisor: int = 1, pad_value: Union[float, int] = 0, bgr_to_rgb: bool = False, rgb_to_bgr: bool = False, non_image_keys: Optional[Tuple[str, List[str]]] = None, non_concentate_keys: Optional[Tuple[str, List[str]]] = None)[source]

Bases: mmengine.model.ImgDataPreprocessor

Image pre-processor for generative models. This class provide normalization and bgr to rgb conversion for image tensor inputs. The input of this classes should be dict which keys are inputs and data_samples.

Besides to process tensor inputs, this class support dict as inputs. - If the value is Tensor and the corresponding key is not contained in _NON_IMAGE_KEYS, it will be processed as image tensor. - If the value is Tensor and the corresponding key belongs to _NON_IMAGE_KEYS, it will not remains unchanged. - If value is string or integer, it will not remains unchanged.

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 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 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_IMAGE_KEYS = ['noise'][source]
_NON_CONCENTATE_KEYS = ['num_batches', 'mode', 'sample_kwargs', 'eq_cfg'][source]
cast_data(data: CastData) CastData[source]

Copying data to the target device.

Parameters

data (dict) – Data returned by DataLoader.

Returns

Inputs and data sample at target device.

Return type

CollatedResult

_preprocess_image_tensor(inputs: torch.Tensor) torch.Tensor[source]

Process image tensor.

Parameters

inputs (Tensor) – List of image tensor to process.

Returns

Processed and stacked image tensor.

Return type

Tensor

process_dict_inputs(batch_inputs: dict) dict[source]

Preprocess dict type inputs.

Parameters

batch_inputs (dict) – Input dict.

Returns

Preprocessed dict.

Return type

dict

forward(data: dict, training: bool = False) dict[source]

Performs normalization、padding and bgr2rgb conversion based on BaseDataPreprocessor.

Parameters
  • data (dict) – Input data to process.

  • training (bool) – Whether to enable training time augmentation. This is ignored for GenDataPreprocessor. Defaults to False.

Returns

Data in the same format as the model input.

Return type

dict

destructor(batch_tensor: torch.Tensor)[source]

Destructor of data processor. Destruct padding, normalization and dissolve batch.

Parameters

batch_tensor (Tensor) – Batched output.

Returns

Destructed output.

Return type

Tensor

Read the Docs v: latest
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.