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
- TypeError – If degrees is not of type integer, float or sequence. 
- TypeError – If translate is not of type sequence. 
- TypeError – If scale is not of type sequence. 
- TypeError – If shear is not of type integer, float or sequence. 
- TypeError – If resample is not of type Inter. 
- TypeError – If fill_value is not of type integer or tuple of integer. 
- ValueError – If degrees is negative. 
- ValueError – If translate is not in range [-1.0, 1.0]. 
- ValueError – If scale is negative. 
- ValueError – If shear is not positive. 
- RuntimeError – If given tensor shape is not <H, W> or <H, W, C>. 
 
 - Supported Platforms:
- CPU
 - 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")