Shortcuts

mmedit.datasets.transforms.crop

Module Contents

Classes

Crop

Crop data to specific size for training.

CropLike

Crop/pad the image in the target_key according to the size of image in

FixedCrop

Crop paired data (at a specific position) to specific size for training.

ModCrop

Mod crop images, used during testing.

PairedRandomCrop

Paried random crop.

RandomResizedCrop

Crop data to random size and aspect ratio.

CropAroundCenter

Randomly crop the images around unknown area in the center 1/4 images.

CropAroundFg

Crop around the whole foreground in the segmentation mask.

CropAroundUnknown

Crop around unknown area with a randomly selected scale.

RandomCropLongEdge

Random crop the given image by the long edge.

CenterCropLongEdge

Center crop the given image by the long edge.

InstanceCrop

Use maskrcnn to detect instances on image.

Attributes

mmdet_apis

mmedit.datasets.transforms.crop.mmdet_apis[源代码]
class mmedit.datasets.transforms.crop.Crop(keys, crop_size, random_crop=True, is_pad_zeros=False)[源代码]

Bases: mmcv.transforms.BaseTransform

Crop data to specific size for training.

参数
  • keys (Sequence[str]) – The images to be cropped.

  • crop_size (Tuple[int]) – Target spatial size (h, w).

  • random_crop (bool) – If set to True, it will random crop image. Otherwise, it will work as center crop. Default: True.

  • is_pad_zeros (bool, optional) – Whether to pad the image with 0 if crop_size is greater than image size. Default: False.

_crop(data)[源代码]
transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.CropLike(target_key, reference_key=None)[源代码]

Bases: mmcv.transforms.BaseTransform

Crop/pad the image in the target_key according to the size of image in the reference_key .

参数
  • target_key (str) – The key needs to be cropped.

  • reference_key (str | None) – The reference key, need its size. Default: None.

transform(results)[源代码]

Transform function.

参数

results (dict) – A dict containing the necessary information and data for augmentation. Require self.target_key and self.reference_key.

返回

A dict containing the processed data and information.

Modify self.target_key.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.FixedCrop(keys, crop_size, crop_pos=None)[源代码]

Bases: mmcv.transforms.BaseTransform

Crop paired data (at a specific position) to specific size for training.

参数
  • keys (Sequence[str]) – The images to be cropped.

  • crop_size (Tuple[int]) – Target spatial size (h, w).

  • crop_pos (Tuple[int]) – Specific position (x, y). If set to None, random initialize the position to crop paired data batch. Default: None.

_crop(data, x_offset, y_offset, crop_w, crop_h)[源代码]
transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.ModCrop(key='gt')[源代码]

Bases: mmcv.transforms.BaseTransform

Mod crop images, used during testing.

Required keys are “scale” and “KEY”, added or modified keys are “KEY”.

参数

key (str) – The key of image. Default: ‘gt’

transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.PairedRandomCrop(gt_patch_size, lq_key='img', gt_key='gt')[源代码]

Bases: mmcv.transforms.BaseTransform

Paried random crop.

It crops a pair of img and gt images with corresponding locations. It also supports accepting img list and gt list. Required keys are “scale”, “lq_key”, and “gt_key”, added or modified keys are “lq_key” and “gt_key”.

参数
  • gt_patch_size (int) – cropped gt patch size.

  • lq_key (str) – Key of LQ img. Default: ‘img’.

  • gt_key (str) – Key of GT img. Default: ‘gt’.

transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.RandomResizedCrop(keys, crop_size, scale=(0.08, 1.0), ratio=(3.0 / 4.0, 4.0 / 3.0), interpolation='bilinear')[源代码]

Bases: mmcv.transforms.BaseTransform

Crop data to random size and aspect ratio.

A crop of a random proportion of the original image and a random aspect ratio of the original aspect ratio is made. The cropped image is finally resized to a given size specified by ‘crop_size’. Modified keys are the attributes specified in “keys”.

This code is partially adopted from torchvision.transforms.RandomResizedCrop: [https://pytorch.org/vision/stable/_modules/torchvision/transforms/ transforms.html#RandomResizedCrop].

参数
  • keys (list[str]) – The images to be resized and random-cropped.

  • crop_size (int | tuple[int]) – Target spatial size (h, w).

  • scale (tuple[float], optional) – Range of the proportion of the original image to be cropped. Default: (0.08, 1.0).

  • ratio (tuple[float], optional) – Range of aspect ratio of the crop. Default: (3. / 4., 4. / 3.).

  • interpolation (str, optional) – Algorithm used for interpolation. It can be only either one of the following: “nearest” | “bilinear” | “bicubic” | “area” | “lanczos”. Default: “bilinear”.

get_params(data)[源代码]

Get parameters for a random sized crop.

参数

data (np.ndarray) – Image of type numpy array to be cropped.

返回

A tuple containing the coordinates of the top left corner and the chosen crop size.

transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.CropAroundCenter(crop_size)[源代码]

Bases: mmcv.transforms.BaseTransform

Randomly crop the images around unknown area in the center 1/4 images.

This cropping strategy is adopted in GCA matting. The unknown area is the same as semi-transparent area. https://arxiv.org/pdf/2001.04069.pdf

It retains the center 1/4 images and resizes the images to ‘crop_size’. Required keys are “fg”, “bg”, “trimap” and “alpha”, added or modified keys are “crop_bbox”, “fg”, “bg”, “trimap” and “alpha”.

参数

crop_size (int | tuple) – Desired output size. If int, square crop is applied.

transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.CropAroundFg(keys, bd_ratio_range=(0.1, 0.4), test_mode=False)[源代码]

Bases: mmcv.transforms.BaseTransform

Crop around the whole foreground in the segmentation mask.

Required keys are “seg” and the keys in argument keys. Meanwhile, “seg” must be in argument keys. Added or modified keys are “crop_bbox” and the keys in argument keys.

参数
  • keys (Sequence[str]) – The images to be cropped. It must contain ‘seg’.

  • bd_ratio_range (tuple, optional) – The range of the boundary (bd) ratio to select from. The boundary ratio is the ratio of the boundary to the minimal bbox that contains the whole foreground given by segmentation. Default to (0.1, 0.4).

  • test_mode (bool) – Whether use test mode. In test mode, the tight crop area of foreground will be extended to the a square. Default to False.

transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

class mmedit.datasets.transforms.crop.CropAroundUnknown(keys, crop_sizes, unknown_source='alpha', interpolations='bilinear')[源代码]

Bases: mmcv.transforms.BaseTransform

Crop around unknown area with a randomly selected scale.

Randomly select the w and h from a list of (w, h). Required keys are the keys in argument keys, added or modified keys are “crop_bbox” and the keys in argument keys. This class assumes value of “alpha” ranges from 0 to 255.

参数
  • keys (Sequence[str]) – The images to be cropped. It must contain ‘alpha’. If unknown_source is set to ‘trimap’, then it must also contain ‘trimap’.

  • crop_sizes (list[int | tuple[int]]) – List of (w, h) to be selected.

  • unknown_source (str, optional) – Unknown area to select from. It must be ‘alpha’ or ‘trimap’. Default to ‘alpha’.

  • interpolations (str | list[str], optional) – Interpolation method of mmcv.imresize. The interpolation operation will be applied when image size is smaller than the crop_size. If given as a list of str, it should have the same length as keys. Or if given as a str all the keys will be resized with the same method. Default to ‘bilinear’.

transform(results)[源代码]

Transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.RandomCropLongEdge(keys='img')[源代码]

Bases: mmcv.transforms.BaseTransform

Random crop the given image by the long edge.

参数

keys (list[str]) – The images to be cropped.

transform(results)[源代码]

Call function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.CenterCropLongEdge(keys='img')[源代码]

Bases: mmcv.transforms.BaseTransform

Center crop the given image by the long edge.

参数

keys (list[str]) – The images to be cropped.

transform(results)[源代码]

Call function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

class mmedit.datasets.transforms.crop.InstanceCrop(config_file, key='img', box_num_upbound=- 1, finesize=256)[源代码]

Bases: mmcv.transforms.BaseTransform

Use maskrcnn to detect instances on image.

Mask R-CNN is used to detect the instance on the image pred_bbox is used to segment the instance on the image

参数
  • config_file (str) – config file name relative to detectron2’s “configs/”

  • key (str) – Unused

  • box_num_upbound (int) – The upper limit on the number of instances in the figure

transform(results: dict) dict[源代码]

The transform function of InstanceCrop.

参数

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

返回

A dict containing the processed data

and information.

返回类型

results (dict)

predict_bbox(image)[源代码]
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.