mindspore.dataset.vision.py_transforms.RandomAffine

class mindspore.dataset.vision.py_transforms.RandomAffine(degrees, translate=None, scale=None, shear=None, resample=Inter.NEAREST, fill_value=0)[source]

Apply Random affine transformation to the input PIL image.

Parameters
  • degrees (Union[int, float, sequence]) – Range of the rotation degrees. If degrees is a number, the range will be (-degrees, degrees). If degrees is a sequence, it should be (min, max).

  • translate (sequence, optional) – Sequence (tx, ty) of maximum translation in x(horizontal) and y(vertical) directions (default=None). The horizontal shift and vertical shift are selected randomly from the range: (-tx*width, tx*width) and (-ty*height, ty*height), respectively. If None, no translations are applied.

  • scale (sequence, optional) – Scaling factor interval (default=None, original scale is used).

  • shear (Union[int, float, sequence], optional) – Range of shear factor (default=None). If shear is an integer, then a shear parallel to the X axis in the range of (-shear, +shear) is applied. If shear is a tuple or list of size 2, then a shear parallel to the X axis in the range of (shear[0], shear[1]) is applied. If shear is a tuple of list of size 4, then a shear parallel to X axis in the range of (shear[0], shear[1]) and a shear parallel to Y axis in the range of (shear[2], shear[3]) is applied. If shear is None, no shear is applied.

  • resample (Inter mode, optional) –

    An optional resampling filter (default=Inter.NEAREST). If omitted, or if the image has mode “1” or “P”, it is set to be Inter.NEAREST. It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC].

    • Inter.BILINEAR, means resample method is bilinear interpolation.

    • Inter.NEAREST, means resample method is nearest-neighbor interpolation.

    • Inter.BICUBIC, means resample method is bicubic interpolation.

  • fill_value (Union[tuple, int], optional) – Optional filling value to fill the area outside the transform in the output image. There must be three elements in the tuple and the value of a single element is within the range [0, 255]. Used only in Pillow versions > 5.0.0 (default=0, filling is performed).

Raises
  • ValueError – If degrees is negative.

  • ValueError – If translation value is not between 0 and 1.

  • ValueError – If scale is not positive.

  • ValueError – If shear is a number but is not positive.

  • TypeError – If degrees is not a number or a list or a tuple. If degrees is a list or tuple, its length is not 2.

  • TypeError – If translate is specified but is not list or a tuple of length 2.

  • TypeError – If scale is not a list or tuple of length 2.

  • TypeError – If shear is not a list or tuple of length 2 or 4.

  • TypeError – If fill_value is not a single integer or a 3-tuple.

Examples

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>> transforms_list = Compose([py_vision.Decode(),
...                            py_vision.RandomAffine(degrees=15, translate=(0.1, 0.1), scale=(0.9, 1.1)),
...                            py_vision.ToTensor()])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")