Shortcuts

mmedit.datasets.transforms.formatting

Module Contents

Classes

PackEditInputs

Pack the inputs data for SR, VFI, matting and inpainting.

ToTensor

Convert some values in results dict to torch.Tensor type in data

Functions

check_if_image(→ bool)

Check if the input value is image or images.

image_to_tensor(img)

Trans image to tensor.

images_to_tensor(value)

Trans image and sequence of frames to tensor.

can_convert_to_image(value)

Judge whether the input value can be converted to image tensor via

mmedit.datasets.transforms.formatting.check_if_image(value: Any) bool[source]

Check if the input value is image or images.

If value is a list or Tuple, recursively check if each element in value is image.

Parameters

value (Any) – The value to be checked.

Returns

If the value is image or sequence of images.

Return type

bool

mmedit.datasets.transforms.formatting.image_to_tensor(img)[source]

Trans image to tensor.

Parameters

img (np.ndarray) – The original image.

Returns

The output tensor.

Return type

Tensor

mmedit.datasets.transforms.formatting.images_to_tensor(value)[source]

Trans image and sequence of frames to tensor.

Parameters

value (np.ndarray | list[np.ndarray] | Tuple[np.ndarray]) – The original image or list of frames.

Returns

The output tensor.

Return type

Tensor

mmedit.datasets.transforms.formatting.can_convert_to_image(value)[source]

Judge whether the input value can be converted to image tensor via images_to_tensor() function.

Parameters

value (any) – The input value.

Returns

If true, the input value can convert to image with

images_to_tensor(), and vice versa.

Return type

bool

class mmedit.datasets.transforms.formatting.PackEditInputs(keys: Tuple[List[str], str, None] = None, pack_all: bool = False)[source]

Bases: mmcv.transforms.base.BaseTransform

Pack the inputs data for SR, VFI, matting and inpainting.

Keys for images include img, gt, ref, mask, gt_heatmap,

trimap, gt_alpha, gt_fg, gt_bg. All of them will be packed into data field of EditDataSample.

pack_all (bool): Whether pack all variables in results to inputs dict.

This is useful when keys of the input dict is not fixed. Please be careful when using this function, because we do not Defaults to False.

Others will be packed into metainfo field of EditDataSample.

transform(results: dict) dict[source]

Method to pack the input data.

Parameters

results (dict) – Result dict from the data pipeline.

Returns

  • ‘inputs’ (obj:torch.Tensor): The forward data of models.

  • ’data_samples’ (obj:EditDataSample): The annotation info of the

    sample.

Return type

dict

__repr__() str[source]

Return repr(self).

class mmedit.datasets.transforms.formatting.ToTensor(keys, to_float32=True)[source]

Bases: mmcv.transforms.base.BaseTransform

Convert some values in results dict to torch.Tensor type in data loader pipeline.

Parameters
  • keys (Sequence[str]) – Required keys to be converted.

  • to_float32 (bool) – Whether convert tensors of images to float32. Default: True.

_data_to_tensor(value)[source]

Convert the value to tensor.

transform(results)[source]

transform function.

Parameters

results (dict) – A dict containing the necessary information and data for augmentation.

Returns

A dict containing the processed data and information.

Return type

dict

__repr__()[source]

Return repr(self).

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.