Shortcuts

RandomCrop

class mmpretrain.datasets.transforms.RandomCrop(crop_size, padding=None, pad_if_needed=False, pad_val=0, padding_mode='constant')[源代码]

在随机位置裁剪给定图像

Required Keys:

  • img

Modified Keys:

  • img

  • img_shape

参数:
  • crop_size (int | Sequence) – Desired output size of the crop. If crop_size is an int instead of sequence like (h, w), a square crop (crop_size, crop_size) is made.

  • padding (int | Sequence, optional) – Optional padding on each border of the image. If a sequence of length 4 is provided, it is used to pad left, top, right, bottom borders respectively. If a sequence of length 2 is provided, it is used to pad left/right, top/bottom borders, respectively. Default: None, which means no padding.

  • pad_if_needed (bool) – It will pad the image if smaller than the desired size to avoid raising an exception. Since cropping is done after padding, the padding seems to be done at a random offset. Default: False.

  • pad_val (Number | Sequence[Number]) – Pixel pad_val value for constant fill. If a tuple of length 3, it is used to pad_val R, G, B channels respectively. Default: 0.

  • padding_mode (str) –

    Type of padding. Defaults to “constant”. Should be one of the following:

    • constant: Pads with a constant value, this value is specified with pad_val.

    • edge: pads with the last value at the edge of the image.

    • reflect: Pads with reflection of image without repeating the last value on the edge. For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode will result in [3, 2, 1, 2, 3, 4, 3, 2].

    • symmetric: Pads with reflection of image repeating the last value on the edge. For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode will result in [2, 1, 1, 2, 3, 4, 4, 3].

transform(results)[源代码]

Transform function to randomly crop images.

参数:

results (dict) – Result dict from loading pipeline.

返回:

Randomly cropped results, ‘img_shape’

key in result dict is updated according to crop size.

返回类型:

dict

Read the Docs v: latest
Versions
latest
stable
mmcls-1.x
mmcls-0.x
dev
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.