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 degrees to select from. If degrees is a number, the range will be (-degrees, degrees). If degrees is a sequence, it should be in shape of (min, max).
translate (sequence, optional) – Maximum absolute fraction sequence in shape of (tx, ty) for horizontal and vertical translations. The horizontal and vertical shifts are randomly selected in the range (-tx * width, tx * width) and (-ty * height, ty * height) respectively. (default=None, no translation will be applied).
scale (sequence, optional) – Scaling factor interval (default=None, keep original scale).
shear (Union[int, float, sequence], optional) – Range of shear factor to select from. If shear is an integer, a shear parallel to the X axis in the range (-shear, shear) will be applied. If shear is a sequence of length 2, a shear parallel to the X axis in the range (shear[0], shear[1]) will be applied. If shear is a sequence of length 4, a shear parallel to the X axis in the range (shear[0], shear[1]) and a shear parallel to the Y axis in the range (shear[2], shear[3]) will be applied. (default=None, no shear will be applied).
resample (Inter, optional) –
An optional resampling filter (default=Inter.NEAREST). If the PIL Image is in mode of “1” or “P”, it is set to Inter.NEAREST by default. It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC].
Inter.BILINEAR, bilinear interpolation.
Inter.NEAREST, nearest-neighbor interpolation.
Inter.BICUBIC, bicubic interpolation.
fill_value (Union[int, tuple], optional) – Pixel fill value for the area outside the transformed image (default=0). If fill_value is an integer, it is used for all RGB channels. If fill_value is a tuple of length 3, it is used to fill R, G, B channels respectively. Only supported with Pillow version > 5.0.0.
- Raises
ValueError – If degrees is negative.
ValueError – If translation is not between 0 and 1.
ValueError – If scale is not positive.
ValueError – If shear is a non positive number.
TypeError – If degrees is not a number or a sequence of length 2.
TypeError – If translate is defined but not a sequence of length 2.
TypeError – If scale is not a sequence of length 2.
TypeError – If shear is not a sequence of length 2 or 4.
TypeError – If fill_value is not an integer or a tuple of length 3.
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")