Shortcuts

mmagic.models.data_preprocessors.mattor_preprocessor

Module Contents

Classes

MattorPreprocessor

DataPreprocessor for matting models.

Attributes

DataSamples

ForwardResults

MEAN_STD_TYPE

mmagic.models.data_preprocessors.mattor_preprocessor.DataSamples[source]
mmagic.models.data_preprocessors.mattor_preprocessor.ForwardResults[source]
mmagic.models.data_preprocessors.mattor_preprocessor.MEAN_STD_TYPE[source]
class mmagic.models.data_preprocessors.mattor_preprocessor.MattorPreprocessor(mean: MEAN_STD_TYPE = [123.675, 116.28, 103.53], std: MEAN_STD_TYPE = [58.395, 57.12, 57.375], output_channel_order: str = 'RGB', proc_trimap: str = 'rescale_to_zero_one', stack_data_sample=True)[source]

Bases: mmagic.models.data_preprocessors.data_preprocessor.DataPreprocessor

DataPreprocessor for matting models.

See base class DataPreprocessor for detailed information.

Workflow as follow :

  • Collate and move data to the target device.

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

  • Normalize image with defined std and mean.

  • Stack inputs to batch_inputs.

Parameters
  • mean (Sequence[float or int], float or int, optional) – The pixel mean of image channels. Noted that normalization operation is performed after channel order conversion. If it is not specified, images will not be normalized. Defaults None.

  • std (Sequence[float or int], float or int, optional) – The pixel standard deviation of image channels. Noted that normalization operation is performed after channel order conversion. If it is not specified, images will not be normalized. Defaults None.

  • proc_trimap (str) – Methods to process gt tensors. Default: ‘rescale_to_zero_one’. Available options are rescale_to_zero_one and as-is.

  • stack_data_sample (bool) – Whether stack a list of data samples to one data sample. Only support with input data samples are DataSamples. Defaults to True.

_proc_batch_trimap(batch_trimaps: torch.Tensor)[source]
_preprocess_data_sample(data_samples: mmagic.utils.typing.SampleList, training: bool) list[source]

Preprocess data samples. When training is True, fields belong to self.data_keys will be converted to self.output_channel_order and divided by 255. When training is False, fields belongs to self.data_keys will be attempted to convert to ‘BGR’ without normalization. The corresponding metainfo related to normalization, channel order conversion will be updated to data sample as well.

Parameters
  • data_samples (List[DataSample]) – A list of data samples to preprocess.

  • training (bool) – Whether in training mode.

Returns

The list of processed data samples.

Return type

list

forward(data: Sequence[dict], training: bool = False) Tuple[torch.Tensor, list][source]

Pre-process input images, trimaps, ground-truth as configured.

Parameters
  • data (Sequence[dict]) – data sampled from dataloader.

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

Returns

Batched inputs and list of data samples.

Return type

Tuple[torch.Tensor, list]

Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.