Shortcuts

mmedit.models.data_preprocessors.edit_data_preprocessor

Module Contents

Classes

EditDataPreprocessor

Basic data pre-processor used for collating and copying data to the

Functions

stack_batch(tensor_list[, pad_size_divisor, pad_args])

Stack multiple tensors to form a batch and pad the images to the max

split_batch(batch_tensor, padded_sizes)

reverse operation of stack_batch.

mmedit.models.data_preprocessors.edit_data_preprocessor.stack_batch(tensor_list: List[torch.Tensor], pad_size_divisor: int = 1, pad_args: dict = dict())[源代码]

Stack multiple tensors to form a batch and pad the images to the max shape use the right bottom padding mode in these images.

If pad_size_divisor > 0, add padding to ensure the shape of each dim is divisible by pad_size_divisor.

参数
  • tensor_list (List[Tensor]) – A list of tensors with the same dim.

  • pad_size_divisor (int) – If pad_size_divisor > 0, add padding to ensure the shape of each dim is divisible by pad_size_divisor. This depends on the model, and many models need to be divisible by 32. Defaults to 1

  • pad_args (dict) – The padding args.

返回

The 4D-tensor or 5D-tensor. Tensor.dim == tensor_list[0].dim + 1 padded_sizes (Tensor): The padded sizes of each tensor.

返回类型

batch_tensor (Tensor)

mmedit.models.data_preprocessors.edit_data_preprocessor.split_batch(batch_tensor: torch.Tensor, padded_sizes: torch.Tensor)[源代码]

reverse operation of stack_batch.

参数
  • batch_tensor (Tensor) – The 4D-tensor or 5D-tensor. Tensor.dim == tensor_list[0].dim + 1

  • padded_sizes (Tensor) – The padded sizes of each tensor.

返回

A list of tensors with the same dim.

返回类型

tensor_list (List[Tensor])

class mmedit.models.data_preprocessors.edit_data_preprocessor.EditDataPreprocessor(mean: Sequence[Union[float, int]] = (0, 0, 0), std: Sequence[Union[float, int]] = (255, 255, 255), pad_size_divisor: int = 1, input_view=(- 1, 1, 1), output_view=None, pad_args: dict = dict())[源代码]

Bases: mmengine.model.BaseDataPreprocessor

Basic data pre-processor used for collating and copying data to the target device in mmediting.

EditDataPreprocessor performs data pre-processing according to the following steps:

  • Collates the data sampled from dataloader.

  • Copies data to the target device.

  • Stacks the input tensor at the first dimension.

and post-processing of the output tensor of model.

TODO: Most editing methods have crop inputs to a same size, batched padding

will be faster.

参数
  • mean (Sequence[float or int]) – The pixel mean of R, G, B channels. Defaults to (0, 0, 0). If mean and std are not specified, ImgDataPreprocessor will normalize images to [0, 1].

  • std (Sequence[float or int]) – The pixel standard deviation of R, G, B channels. (255, 255, 255). If mean and std are not specified, ImgDataPreprocessor will normalize images to [0, 1].

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

  • input_view (Tuple | List) – Tensor view of mean and std for input (without batch). Defaults to (-1, 1, 1) for (C, H, W).

  • output_view (Tuple | List | None) – Tensor view of mean and std for output (without batch). If None, output_view=input_view. Defaults: None.

  • pad_args (dict) – Args of F.pad. Default: dict().

forward(data: Sequence[dict], training: bool = False) Tuple[torch.Tensor, Optional[list]][源代码]

Pre-process the data into the model input format.

After the data pre-processing of collate_data(), forward will stack the input tensor list to a batch tensor at the first dimension.

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

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

返回

Data in the same format as the model input.

返回类型

Tuple[torch.Tensor, Optional[list]]

destructor(batch_tensor: torch.Tensor)[源代码]

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

参数

batch_tensor (Tensor) – Batched output.

返回

Destructed output.

返回类型

Tensor

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

Free document hosting provided by Read the Docs.