tinyms.vision¶
This module is to support vision augmentations. transforms is a high performance image augmentation module which is developed with C++ OpenCV.
-
class
tinyms.vision.
ImageViewer
(image, label=None)[source]¶ ImageViewer is a class defined for visualizing the input image.
- Parameters
image (Union[PIL.Image, numpy.ndarray]) – image input.
label (str, optional) – specifies the label of this image. Default: None.
- Raises
TypeError – When image input is not numpy.ndarray or PIL.Image.
-
draw
(pred_res, labels)[source]¶ Draw the predicting boxes on the picture and show the visualized picture.
- Parameters
Note
This function is only valid when being called in interactive environment, such like Jupyter notebook.
Examples
>>> form PIL import Image >>> >>> img = Image.open('example.jpg') >>> img_viewer = ImageViewer(img) >>> labels = ['1', '2', '3'] >>> img_viewer.draw(pred_res, labels)
-
show
()[source]¶ Directly show the visualized picture.
Note
This function is only valid when being called in interactive environment, such like Jupyter notebook.
Examples
>>> form PIL import Image >>> >>> img = Image.open('example.jpg') >>> img_viewer = ImageViewer(img, label='cat') >>> img_viewer.show()
-
class
tinyms.vision.
Inter
[source]¶ Interpolation Modes.
Possible enumeration values are: Inter.NEAREST, Inter.ANTIALIAS, Inter.LINEAR, Inter.BILINEAR, Inter.CUBIC, Inter.BICUBIC, Inter.AREA, Inter.PILCUBIC.
Inter.NEAREST: means interpolation method is nearest-neighbor interpolation.
Inter.ANTIALIAS: means the interpolation method is antialias interpolation.
Inter.LINEAR: means interpolation method is bilinear interpolation, here is the same as Inter.BILINEAR.
Inter.BILINEAR: means interpolation method is bilinear interpolation.
Inter.CUBIC: means the interpolation method is bicubic interpolation, here is the same as Inter.BICUBIC.
Inter.BICUBIC: means the interpolation method is bicubic interpolation.
Inter.AREA: means interpolation method is pixel area interpolation.
Inter.PILCUBIC: means interpolation method is bicubic interpolation like implemented in pillow, input should be in 3 channels format.
-
class
tinyms.vision.
Border
[source]¶ Padding Mode, Border Type.
Possible enumeration values are: Border.CONSTANT, Border.EDGE, Border.REFLECT, Border.SYMMETRIC.
Border.CONSTANT: means it fills the border with constant values.
Border.EDGE: means it pads with the last value on the edge.
Border.REFLECT: means it reflects the values on the edge omitting the last value of edge.
Border.SYMMETRIC: means it reflects the values on the edge repeating the last value of edge.
Note: This class derived from class str to support json serializable.
-
class
tinyms.vision.
ImageBatchFormat
[source]¶ Data Format of images after batch operation.
Possible enumeration values are: ImageBatchFormat.NHWC, ImageBatchFormat.NCHW.
ImageBatchFormat.NHWC: in orders like, batch N, height H, width W, channels C to store the data.
ImageBatchFormat.NCHW: in orders like, batch N, channels C, height H, width W to store the data.
-
tinyms.vision.
ssd_bboxes_encode
(boxes)[source]¶ Labels anchors with ground truth inputs.
- Parameters
boxes (numpy.ndarray) – Ground truth with shape [N, 5], for each row, it stores [ymin, xmin, ymax, xmax, cls].
- Returns
numpy.ndarray, location ground truth with shape [num_anchors, 4]. numpy.ndarray, class ground truth with shape [num_anchors, 1]. numpy.ndarray, number of positives in an image.
-
tinyms.vision.
ssd_bboxes_filter
(boxes, box_scores, image_shape)[source]¶ Filter predict boxes with minimum score and nms threshold.
- Parameters
boxes (numpy.ndarray) – Ground truth with shape [N, 4], for each row, it stores [ymin, xmin, ymax, xmax].
box_scores (numpy.ndarray) – Class scores with shape [N, 21].
image_shape (tuple) – Shape of original image with the format [h, w].
- Returns
list[list[float]], ground truth with shape [N, 4], for each row, it stores [ymin, xmin, ymax, xmax]. list[list[float]], class scores with shape [N, 21]. list[list[int]], class label with shape [N, 21].
-
class
tinyms.vision.
MnistTransform
(configs=None)[source]¶ Mnist dataset transform class.
- Inputs:
img (Union[numpy.ndarray, PIL.Image]): Image to be transformed in Mnist-style.
- Outputs:
numpy.ndarray, transformed image.
Examples
>>> from PIL import Image >>> from tinyms.vision import MnistTransform >>> >>> mnist_transform = MnistTransform() >>> img = Image.open('object_detection.jpg') >>> img = mnist_transform(img)
-
apply_ds
(mnist_ds, repeat_size=1, batch_size=32, num_parallel_workers=None)[source]¶ Apply preprocess operation on MnistDataset instance.
- Parameters
mnist_ds (data.MnistDataset) – MnistDataset instance.
repeat_size (int) – The repeat size of dataset. Default: 1.
batch_size (int) – Batch size. Default: 32.
num_parallel_workers (int) – The number of concurrent workers. Default: None.
- Returns
data.MnistDataset, the preprocessed MnistDataset instance.
Examples
>>> from tinyms.vision import MnistTransform >>> >>> mnist_transform = MnistTransform() >>> mnist_ds = mnist_transform.apply_ds(mnist_ds)
-
postprocess
(input, strategy='TOP1_CLASS')¶ Apply postprocess operation for prediction result.
- Parameters
input (numpy.ndarray) – Prediction result.
strategy (str) – Specifies the postprocess strategy. Default: TOP1_CLASS.
- Returns
str, the postprocess result.
-
class
tinyms.vision.
Cifar10Transform
(configs=None)[source]¶ Cifar10 dataset transform class.
- Inputs:
img (Union[numpy.ndarray, PIL.Image]): Image to be transformed in Cifar10-style.
- Outputs:
numpy.ndarray, Transformed image.
Examples
>>> from PIL import Image >>> from tinyms.vision import Cifar10Transform >>> >>> cifar10_transform = Cifar10Transform() >>> img = Image.open('object_detection.jpg') >>> img = cifar10_transform(img)
“””
-
apply_ds
(cifar10_ds, repeat_size=1, batch_size=32, num_parallel_workers=None, is_training=True)[source]¶ Apply preprocess operation on Cifar10Dataset instance.
- Parameters
cifar10_ds (data.Cifar10Dataset) – Cifar10Dataset instance.
repeat_size (int) – The repeat size of dataset. Default: 1.
batch_size (int) – Batch size. Default: 32.
num_parallel_workers (int) – The number of concurrent workers. Default: None.
is_training (bool) – Specifies if is in training step. Default: True.
- Returns
data.Cifar10Dataset, the preprocessed Cifar10Dataset instance.
Examples
>>> from tinyms.vision import Cifar10Transform >>> >>> cifar10_transform = Cifar10Transform() >>> cifar10_ds = cifar10_transform.apply_ds(cifar10_ds)
-
postprocess
(input, strategy='TOP1_CLASS')¶ Apply postprocess operation for prediction result.
- Parameters
input (numpy.ndarray) – Prediction result.
strategy (str) – Specifies the postprocess strategy. Default: TOP1_CLASS.
- Returns
str, the postprocess result.
-
class
tinyms.vision.
ImageFolderTransform
(configs=None)[source]¶ ImageFolder dataset transform class.
- Inputs:
img (Union[numpy.ndarray, PIL.Image]): Image to be transformed in ImageFolder-style.
- Outputs:
numpy.ndarray, transformed image.
Examples
>>> from PIL import Image >>> from tinyms.vision import ImageFolderTransform >>> >>> imagefolder_transform = ImageFolderTransform() >>> img = Image.open('object_detection.jpg') >>> img = imagefolder_transform(img)
-
apply_ds
(imagefolder_ds, repeat_size=1, batch_size=32, num_parallel_workers=None, is_training=True)[source]¶ Apply preprocess operation on ImageFolderDataset instance.
- Parameters
cifar10_ds (data.ImageFolderDataset) – ImageFolderDataset instance.
repeat_size (int) – The repeat size of dataset. Default: 1.
batch_size (int) – Batch size. Default: 32.
num_parallel_workers (int) – The number of concurrent workers. Default: None.
is_training (bool) – Specifies if is in training step. Default: True.
- Returns
data.ImageFolderDataset, the preprocessed ImageFolderDataset instance.
Examples
>>> from tinyms.vision import ImageFolderTransform >>> >>> imagefolder_transform = ImageFolderTransform() >>> imagefolder_ds = imagefolder_transform.apply_ds(imagefolder_ds)
-
postprocess
(input, strategy='TOP1_CLASS')¶ Apply postprocess operation for prediction result.
- Parameters
input (numpy.ndarray) – Prediction result.
strategy (str) – Specifies the postprocess strategy. Default: TOP1_CLASS.
- Returns
str, the postprocess result.
-
class
tinyms.vision.
VOCTransform
(configs=None)[source]¶ VOC dataset transform class.
- Inputs:
img (Union[numpy.ndarray, PIL.Image]): Image to be transformed in VOC-style.
- Outputs:
numpy.ndarray, transformed image.
Examples
>>> from PIL import Image >>> from tinyms.vision import VOCTransform >>> >>> voc_transform = VOCTransform() >>> img = Image.open('object_detection.jpg') >>> img = voc_transform(img)
-
apply_ds
(voc_ds, repeat_size=1, batch_size=32, num_parallel_workers=None, is_training=True)[source]¶ Apply preprocess operation on VOCDataset instance.
- Parameters
voc_ds (data.VOCDataset) – VOCDataset instance.
repeat_size (int) – The repeat size of dataset. Default: 1.
batch_size (int) – Batch size. Default: 32.
num_parallel_workers (int) – The number of concurrent workers. Default: None.
is_training (bool) – Specifies if is in training step. Default: True.
- Returns
data.VOCDataset, the preprocessed VOCDataset instance.
Examples
>>> from tinyms.vision import VOCTransform >>> >>> VOC_transform = VOCTransform() >>> voc_ds = voc_transform.apply_ds(voc_ds)
-
postprocess
(input, image_shape, strategy='TOP1_CLASS')[source]¶ Apply postprocess operation for prediction result.
- Parameters
input (numpy.ndarray) – Prediction result.
image_shape (tuple) – Image shape.
strategy (str) – Specifies the postprocess strategy. Default: TOP1_CLASS.
- Returns
dict, the postprocess result.
-
class
tinyms.vision.
ShanshuiTransform
(configs=None)[source]¶ Shanshui dataset transform class.
- Inputs:
img (Union[numpy.ndarray, PIL.Image]): Image to be transformed in VOC-style.
- Outputs:
numpy.ndarray, transformed image.
Examples
>>> from PIL import Image >>> from tinyms.vision import ShanshuiTransform >>> >>> shanshui_transform = ShanshuiTransform() >>> img = Image.open('object_detection.jpg') >>> img = shanshui_transform(img)
-
apply_ds
(voc_ds, repeat_size=1, batch_size=32, num_parallel_workers=None, is_training=True)¶ Apply preprocess operation on VOCDataset instance.
- Parameters
voc_ds (data.VOCDataset) – VOCDataset instance.
repeat_size (int) – The repeat size of dataset. Default: 1.
batch_size (int) – Batch size. Default: 32.
num_parallel_workers (int) – The number of concurrent workers. Default: None.
is_training (bool) – Specifies if is in training step. Default: True.
- Returns
data.VOCDataset, the preprocessed VOCDataset instance.
Examples
>>> from tinyms.vision import VOCTransform >>> >>> VOC_transform = VOCTransform() >>> voc_ds = voc_transform.apply_ds(voc_ds)
-
postprocess
(input, image_shape, strategy='TOP1_CLASS')¶ Apply postprocess operation for prediction result.
- Parameters
input (numpy.ndarray) – Prediction result.
image_shape (tuple) – Image shape.
strategy (str) – Specifies the postprocess strategy. Default: TOP1_CLASS.
- Returns
dict, the postprocess result.
-
class
tinyms.vision.
CycleGanDatasetTransform
(configs=None)[source]¶ CycleGan dataset transform class.
- Inputs:
img (Union[numpy.ndarray, PIL.Image]): Image to be transformed in city_scape.
- Outputs:
numpy.ndarray, transformed image.
Examples
>>> from PIL import Image >>> from tinyms.vision import CycleGanDatasetTransform >>> >>> cyclegan_transform = CycleGanDatasetTransform() >>> img = Image.open('object_detection.jpg') >>> img = cyclegan_transform(img)
-
apply_ds
(gan_generator_ds, repeat_size=1, batch_size=1, num_parallel_workers=1, shuffle=True, phase='train')[source]¶ Apply preprocess operation on GeneratorDataset instance.
- Parameters
gan_generator_ds (data.GeneratorDataset) – GeneratorDataset instance.
repeat_size (int) – The repeat size of dataset. Default: 1.
batch_size (int) – Batch size. Default: 32.
num_parallel_workers (int) – The number of concurrent workers. Default: 1.
shuffle (bool) – Specifies if applying shuffle operation. Default: True.
phase (str) – Specifies the current phase. Default: train.
- Returns
data.GeneratorDataset, the preprocessed GeneratorDataset instance.
Examples
>>> from tinyms.vision import CycleGanDatasetTransform >>> >>> cyclegan_transform = CycleGanDatasetTransform() >>> gan_generator_ds = cyclegan_transform.apply_ds(gan_generator_ds)
- Raises
TypeError – If gan_generator_ds is not instance of GeneratorDataset.
-
class
tinyms.vision.
AutoContrast
(cutoff=0.0, ignore=None)[source]¶ Apply automatic contrast on input image. This operator calculates histogram of image, reassign cutoff percent of lightest pixels from histogram to 255, and reassign cutoff percent of darkest pixels from histogram to 0.
- Parameters
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.AutoContrast(cutoff=10.0, ignore=[10, 20])] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
BoundingBoxAugment
(transform, ratio=0.3)[source]¶ Apply a given image transform on a random selection of bounding box regions of a given image.
- Parameters
transform – C++ transformation operator to be applied on random selection of bounding box regions of a given image.
ratio (float, optional) – Ratio of bounding boxes to apply augmentation on. Range: [0, 1] (default=0.3).
Examples
>>> # set bounding box operation with ratio of 1 to apply rotation on all bounding boxes >>> bbox_aug_op = c_vision.BoundingBoxAugment(c_vision.RandomRotation(90), 1) >>> # map to apply ops >>> image_folder_dataset = image_folder_dataset.map(operations=[bbox_aug_op], ... input_columns=["image", "bbox"], ... output_columns=["image", "bbox"], ... column_order=["image", "bbox"])
-
class
tinyms.vision.
CenterCrop
(size)[source]¶ Crop the input image at the center to the given size. If input image size is smaller than output size, input image will be padded with 0 before cropping.
- Parameters
size (Union[int, sequence]) – The output size of the cropped image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
Examples
>>> # crop image to a square >>> transforms_list1 = [c_vision.Decode(), c_vision.CenterCrop(50)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list1, ... input_columns=["image"]) >>> # crop image to portrait style >>> transforms_list2 = [c_vision.Decode(), c_vision.CenterCrop((60, 40))] >>> image_folder_dataset_1 = image_folder_dataset_1.map(operations=transforms_list2, ... input_columns=["image"])
-
class
tinyms.vision.
CutMixBatch
(image_batch_format, alpha=1.0, prob=1.0)[source]¶ Apply CutMix transformation on input batch of images and labels. Note that you need to make labels into one-hot format and batched before calling this operator.
- Parameters
image_batch_format (Image Batch Format) – The method of padding. Can be any of [ImageBatchFormat.NHWC, ImageBatchFormat.NCHW].
alpha (float, optional) – hyperparameter of beta distribution (default = 1.0).
prob (float, optional) – The probability by which CutMix is applied to each image (default = 1.0).
Examples
>>> from mindspore.dataset.vision import ImageBatchFormat >>> onehot_op = c_transforms.OneHot(num_classes=10) >>> image_folder_dataset= image_folder_dataset.map(operations=onehot_op, ... input_columns=["label"]) >>> cutmix_batch_op = c_vision.CutMixBatch(ImageBatchFormat.NHWC, 1.0, 0.5) >>> image_folder_dataset = image_folder_dataset.batch(5) >>> image_folder_dataset = image_folder_dataset.map(operations=cutmix_batch_op, ... input_columns=["image", "label"])
-
class
tinyms.vision.
CutOut
(length, num_patches=1)[source]¶ Randomly cut (mask) out a given number of square patches from the input image array.
- Parameters
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.CutOut(80, num_patches=10)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
Decode
(rgb=True)[source]¶ Decode the input image in RGB mode(default) or BGR mode(deprecated).
- Parameters
rgb (bool, optional) – Mode of decoding input image (default=True). If True means format of decoded image is RGB else BGR(deprecated).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlip()] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
Equalize
[source]¶ Apply histogram equalization on input image.
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.Equalize()] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
Grayscale
(num_output_channels=1)[source]¶ Convert the input PIL Image to grayscale.
- Parameters
num_output_channels (int) – Number of channels of the output grayscale image, which can be 1 or 3 (default=1). If num_output_channels is 3, the returned image will have 3 identical RGB channels.
Examples
>>> from mindspore.dataset.transforms.py_transforms import Compose >>> transforms_list = Compose([py_vision.Decode(), ... py_vision.Grayscale(3), ... py_vision.ToTensor()]) >>> # apply the transform to dataset through map function >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns="image")
-
classmethod
from_json
(json_string)¶ Base from_json for Python tensor operations class
-
to_json
()¶ Base to_json for Python tensor operations class
-
class
tinyms.vision.
HWC2CHW
[source]¶ Transpose the input image from shape (H, W, C) to shape (C, H, W). The input image should be 3 channels image.
Examples
>>> transforms_list = [c_vision.Decode(), ... c_vision.RandomHorizontalFlip(0.75), ... c_vision.RandomCrop(512), ... c_vision.HWC2CHW()] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
Invert
[source]¶ Apply invert on input image in RGB mode. This operator will reassign every pixel to (255 - pixel).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.Invert()] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
MixUpBatch
(alpha=1.0)[source]¶ Apply MixUp transformation on input batch of images and labels. Each image is multiplied by a random weight (lambda) and then added to a randomly selected image from the batch multiplied by (1 - lambda). The same formula is also applied to the one-hot labels. The lambda is generated based on the specified alpha value. Two coefficients x1, x2 are randomly generated in the range [alpha, 1], and lambda = (x1 / (x1 + x2)). Note that you need to make labels into one-hot format and batched before calling this operator.
- Parameters
alpha (float, optional) – Hyperparameter of beta distribution (default = 1.0).
Examples
>>> onehot_op = c_transforms.OneHot(num_classes=10) >>> image_folder_dataset= image_folder_dataset.map(operations=onehot_op, ... input_columns=["label"]) >>> mixup_batch_op = c_vision.MixUpBatch(alpha=0.9) >>> image_folder_dataset = image_folder_dataset.batch(5) >>> image_folder_dataset = image_folder_dataset.map(operations=mixup_batch_op, ... input_columns=["image", "label"])
-
class
tinyms.vision.
Normalize
(mean, std)[source]¶ Normalize the input image with respect to mean and standard deviation. This operator will normalize the input image with: output[channel] = (input[channel] - mean[channel]) / std[channel], where channel >= 1.
- Parameters
mean (sequence) – List or tuple of mean values for each channel, with respect to channel order. The mean values must be in range [0.0, 255.0].
std (sequence) – List or tuple of standard deviations for each channel, with respect to channel order. The standard deviation values must be in range (0.0, 255.0].
Examples
>>> decode_op = c_vision.Decode() >>> normalize_op = c_vision.Normalize(mean=[121.0, 115.0, 100.0], std=[70.0, 68.0, 71.0]) >>> transforms_list = [decode_op, normalize_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
Pad
(padding, fill_value=0, padding_mode=<Border.CONSTANT: 'constant'>)[source]¶ Pad the image according to padding parameters.
- Parameters
padding (Union[int, sequence]) – The number of pixels to pad the image. If a single number is provided, it pads all borders with this value. If a tuple or lists of 2 values are provided, it pads the (left and top) with the first value and (right and bottom) with the second value. If 4 values are provided as a list or tuple, it pads the left, top, right and bottom respectively.
fill_value (Union[int, tuple], optional) – The pixel intensity of the borders, only valid for padding_mode Border.CONSTANT. If it is a 3-tuple, it is used to fill R, G, B channels respectively. If it is an integer, it is used for all RGB channels. The fill_value values must be in range [0, 255] (default=0).
padding_mode (Border mode, optional) –
The method of padding (default=Border.CONSTANT). Can be any of [Border.CONSTANT, Border.EDGE, Border.REFLECT, Border.SYMMETRIC].
Border.CONSTANT, means it fills the border with constant values.
Border.EDGE, means it pads with the last value on the edge.
Border.REFLECT, means it reflects the values on the edge omitting the last value of edge.
Border.SYMMETRIC, means it reflects the values on the edge repeating the last value of edge.
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.Pad([100, 100, 100, 100])] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
tinyms.vision.
PILRandomHorizontalFlip
¶ alias of
mindspore.dataset.vision.py_transforms.RandomHorizontalFlip
-
class
tinyms.vision.
RandomAffine
(degrees, translate=None, scale=None, shear=None, resample=<Inter.NEAREST: 0>, fill_value=0)[source]¶ Apply Random affine transformation to the input image.
- Parameters
degrees (int or float or 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_min, tx_max, ty_min, ty_max) of minimum/maximum translation in x(horizontal) and y(vertical) directions (default=None). The horizontal and vertical shift is selected randomly from the range: (tx_min*width, tx_max*width) and (ty_min*height, ty_max*height), respectively. If a tuple or list of size 2, then a translate parallel to the X axis in the range of (translate[0], translate[1]) is applied. If a tuple of list of size 4, then a translate parallel to the X axis in the range of (translate[0], translate[1]) and a translate parallel to the Y axis in the range of (translate[2], translate[3]) are applied. If None, no translation is applied.
scale (sequence, optional) – Scaling factor interval (default=None, original scale is used).
shear (int or float or sequence, optional) – Range of shear factor (default=None). If a number, then a shear parallel to the X axis in the range of (-shear, +shear) is applied. If 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 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 None, no shear is applied.
resample (Inter mode, optional) –
An optional resampling filter (default=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 (tuple or int, optional) – Optional fill_value to fill the area outside the transform in the output image. There must be three elements in tuple and the value of single element is [0, 255]. (default=0, filling is performed).
- Raises
ValueError – If degrees is negative.
ValueError – If translation value is not between -1 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 or 4.
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.vision import Inter >>> decode_op = c_vision.Decode() >>> random_affine_op = c_vision.RandomAffine(degrees=15, ... translate=(-0.1, 0.1, 0, 0), ... scale=(0.9, 1.1), ... resample=Inter.NEAREST) >>> transforms_list = [decode_op, random_affine_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomColor
(degrees=(0.1, 1.9))[source]¶ Adjust the color of the input image by a fixed or random degree. This operation works only with 3-channel color images.
- Parameters
degrees (sequence, optional) – Range of random color adjustment degrees. It should be in (min, max) format. If min=max, then it is a single fixed magnitude operation (default=(0.1, 1.9)).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomColor((0.5, 2.0))] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomColorAdjust
(brightness=(1, 1), contrast=(1, 1), saturation=(1, 1), hue=(0, 0))[source]¶ Randomly adjust the brightness, contrast, saturation, and hue of the input image.
- Parameters
brightness (Union[float, list, tuple], optional) – Brightness adjustment factor (default=(1, 1)). Cannot be negative. If it is a float, the factor is uniformly chosen from the range [max(0, 1-brightness), 1+brightness]. If it is a sequence, it should be [min, max] for the range.
contrast (Union[float, list, tuple], optional) – Contrast adjustment factor (default=(1, 1)). Cannot be negative. If it is a float, the factor is uniformly chosen from the range [max(0, 1-contrast), 1+contrast]. If it is a sequence, it should be [min, max] for the range.
saturation (Union[float, list, tuple], optional) – Saturation adjustment factor (default=(1, 1)). Cannot be negative. If it is a float, the factor is uniformly chosen from the range [max(0, 1-saturation), 1+saturation]. If it is a sequence, it should be [min, max] for the range.
hue (Union[float, list, tuple], optional) – Hue adjustment factor (default=(0, 0)). If it is a float, the range will be [-hue, hue]. Value should be 0 <= hue <= 0.5. If it is a sequence, it should be [min, max] where -0.5 <= min <= max <= 0.5.
Examples
>>> decode_op = c_vision.Decode() >>> transform_op = c_vision.RandomColorAdjust(brightness=(0.5, 1), ... contrast=(0.4, 1), ... saturation=(0.3, 1)) >>> transforms_list = [decode_op, transform_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomCrop
(size, padding=None, pad_if_needed=False, fill_value=0, padding_mode=<Border.CONSTANT: 'constant'>)[source]¶ Crop the input image at a random location. If input image size is smaller than output size, input image will be padded before cropping.
Note
If the input image is more than one, then make sure that the image size is the same.
- Parameters
size (Union[int, sequence]) – The output size of the cropped image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
padding (Union[int, sequence], optional) – The number of pixels to pad the image (default=None). If padding is not None, pad image first with padding values. If a single number is provided, pad all borders with this value. If a tuple or lists of 2 values are provided, pad the (left and top) with the first value and (right and bottom) with the second value. If 4 values are provided as a list or tuple, pad the left, top, right and bottom respectively.
pad_if_needed (bool, optional) – Pad the image if either side is smaller than the given output size (default=False).
fill_value (Union[int, tuple], optional) – The pixel intensity of the borders, only valid for padding_mode Border.CONSTANT. If it is a 3-tuple, it is used to fill R, G, B channels respectively. If it is an integer, it is used for all RGB channels. The fill_value values must be in range [0, 255] (default=0).
padding_mode (Border mode, optional) –
The method of padding (default=Border.CONSTANT). It can be any of [Border.CONSTANT, Border.EDGE, Border.REFLECT, Border.SYMMETRIC].
Border.CONSTANT, means it fills the border with constant values.
Border.EDGE, means it pads with the last value on the edge.
Border.REFLECT, means it reflects the values on the edge omitting the last value of edge.
Border.SYMMETRIC, means it reflects the values on the edge repeating the last value of edge.
Examples
>>> from mindspore.dataset.vision import Border >>> decode_op = c_vision.Decode() >>> random_crop_op = c_vision.RandomCrop(512, [200, 200, 200, 200], padding_mode=Border.EDGE) >>> transforms_list = [decode_op, random_crop_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomCropDecodeResize
(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=<Inter.BILINEAR: 2>, max_attempts=10)[source]¶ A combination of Crop, Decode and Resize. It will get better performance for JPEG images. This operator will crop the input image at a random location, decode the cropped image in RGB mode, and resize the decoded image.
- Parameters
size (Union[int, sequence]) – The output size of the resized image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
scale (list, tuple, optional) – Range [min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).
ratio (list, tuple, optional) – Range [min, max) of aspect ratio to be cropped (default=(3. / 4., 4. / 3.)).
interpolation (Inter mode, optional) –
Image interpolation mode for resize operator(default=Inter.BILINEAR). It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC].
Inter.BILINEAR, means interpolation method is bilinear interpolation.
Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
Inter.BICUBIC, means interpolation method is bicubic interpolation.
max_attempts (int, optional) – The maximum number of attempts to propose a valid crop_area (default=10). If exceeded, fall back to use center_crop instead.
Examples
>>> from mindspore.dataset.vision import Inter >>> resize_crop_decode_op = c_vision.RandomCropDecodeResize(size=(50, 75), ... scale=(0.25, 0.5), ... interpolation=Inter.NEAREST, ... max_attempts=5) >>> transforms_list = [resize_crop_decode_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomCropWithBBox
(size, padding=None, pad_if_needed=False, fill_value=0, padding_mode=<Border.CONSTANT: 'constant'>)[source]¶ Crop the input image at a random location and adjust bounding boxes accordingly.
- Parameters
size (Union[int, sequence]) – The output size of the cropped image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
padding (Union[int, sequence], optional) – The number of pixels to pad the image (default=None). If padding is not None, first pad image with padding values. If a single number is provided, pad all borders with this value. If a tuple or lists of 2 values are provided, pad the (left and top) with the first value and (right and bottom) with the second value. If 4 values are provided as a list or tuple, pad the left, top, right and bottom respectively.
pad_if_needed (bool, optional) – Pad the image if either side is smaller than the given output size (default=False).
fill_value (Union[int, tuple], optional) – The pixel intensity of the borders, only valid for padding_mode Border.CONSTANT. If it is a 3-tuple, it is used to fill R, G, B channels respectively. If it is an integer, it is used for all RGB channels. The fill_value values must be in range [0, 255] (default=0).
padding_mode (Border mode, optional) –
The method of padding (default=Border.CONSTANT). It can be any of [Border.CONSTANT, Border.EDGE, Border.REFLECT, Border.SYMMETRIC].
Border.CONSTANT, means it fills the border with constant values.
Border.EDGE, means it pads with the last value on the edge.
Border.REFLECT, means it reflects the values on the edge omitting the last value of edge.
Border.SYMMETRIC, means it reflects the values on the edge repeating the last value of edge.
Examples
>>> decode_op = c_vision.Decode() >>> random_crop_with_bbox_op = c_vision.RandomCropWithBBox([512, 512], [200, 200, 200, 200]) >>> transforms_list = [decode_op, random_crop_with_bbox_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomHorizontalFlip
(prob=0.5)[source]¶ Randomly flip the input image horizontally with a given probability.
- Parameters
prob (float, optional) – Probability of the image being flipped (default=0.5).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlip(0.75)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomHorizontalFlipWithBBox
(prob=0.5)[source]¶ Flip the input image horizontally randomly with a given probability and adjust bounding boxes accordingly.
- Parameters
prob (float, optional) – Probability of the image being flipped (default=0.5).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlipWithBBox(0.70)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomPosterize
(bits=(8, 8))[source]¶ Reduce the number of bits for each color channel to posterize the input image randomly with a given probability.
- Parameters
bits (sequence or int, optional) – Range of random posterize to compress image. Bits values must be in range of [1,8], and include at least one integer value in the given range. It must be in (min, max) or integer format. If min=max, then it is a single fixed magnitude operation (default=(8, 8)).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomPosterize((6, 8))] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomResize
(size)[source]¶ Resize the input image using a randomly selected interpolation mode.
- Parameters
size (Union[int, sequence]) – The output size of the resized image. If size is an integer, smaller edge of the image will be resized to this value with the same image aspect ratio. If size is a sequence of length 2, it should be (height, width).
Examples
>>> # randomly resize image, keeping aspect ratio >>> transforms_list1 = [c_vision.Decode(), c_vision.RandomResize(50)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list1, ... input_columns=["image"]) >>> # randomly resize image to landscape style >>> transforms_list2 = [c_vision.Decode(), c_vision.RandomResize((40, 60))] >>> image_folder_dataset_1 = image_folder_dataset_1.map(operations=transforms_list2, ... input_columns=["image"])
-
class
tinyms.vision.
RandomResizedCrop
(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=<Inter.BILINEAR: 2>, max_attempts=10)[source]¶ Crop the input image to a random size and aspect ratio. This operator will crop the input image randomly, and resize the cropped image using a selected interpolation mode.
Note
If the input image is more than one, then make sure that the image size is the same.
- Parameters
size (Union[int, sequence]) – The output size of the resized image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
scale (list, tuple, optional) – Range [min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).
ratio (list, tuple, optional) – Range [min, max) of aspect ratio to be cropped (default=(3. / 4., 4. / 3.)).
interpolation (Inter mode, optional) –
Image interpolation mode for resize operator (default=Inter.BILINEAR). It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC, Inter.PILCUBIC].
Inter.BILINEAR, means interpolation method is bilinear interpolation.
Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
Inter.BICUBIC, means interpolation method is bicubic interpolation.
Inter.AREA, means interpolation method is pixel area interpolation.
Inter.PILCUBIC, means interpolation method is bicubic interpolation like implemented in pillow, input should be in 3 channels format.
max_attempts (int, optional) – The maximum number of attempts to propose a valid crop_area (default=10). If exceeded, fall back to use center_crop instead.
Examples
>>> from mindspore.dataset.vision import Inter >>> decode_op = c_vision.Decode() >>> resize_crop_op = c_vision.RandomResizedCrop(size=(50, 75), scale=(0.25, 0.5), ... interpolation=Inter.BILINEAR) >>> transforms_list = [decode_op, resize_crop_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomResizedCropWithBBox
(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=<Inter.BILINEAR: 2>, max_attempts=10)[source]¶ Crop the input image to a random size and aspect ratio and adjust bounding boxes accordingly.
- Parameters
size (Union[int, sequence]) – The size of the output image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
scale (list, tuple, optional) – Range (min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).
ratio (list, tuple, optional) – Range (min, max) of aspect ratio to be cropped (default=(3. / 4., 4. / 3.)).
interpolation (Inter mode, optional) –
Image interpolation mode (default=Inter.BILINEAR). It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC].
Inter.BILINEAR, means interpolation method is bilinear interpolation.
Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
Inter.BICUBIC, means interpolation method is bicubic interpolation.
max_attempts (int, optional) – The maximum number of attempts to propose a valid crop area (default=10). If exceeded, fall back to use center crop instead.
Examples
>>> from mindspore.dataset.vision import Inter >>> decode_op = c_vision.Decode() >>> bbox_op = c_vision.RandomResizedCropWithBBox(size=50, interpolation=Inter.NEAREST) >>> transforms_list = [decode_op, bbox_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomResizeWithBBox
(size)[source]¶ Tensor operation to resize the input image using a randomly selected interpolation mode and adjust bounding boxes accordingly.
- Parameters
size (Union[int, sequence]) – The output size of the resized image. If size is an integer, smaller edge of the image will be resized to this value with the same image aspect ratio. If size is a sequence of length 2, it should be (height, width).
Examples
>>> # randomly resize image with bounding boxes, keeping aspect ratio >>> transforms_list1 = [c_vision.Decode(), c_vision.RandomResizeWithBBox(60)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list1, ... input_columns=["image"]) >>> # randomly resize image with bounding boxes to portrait style >>> transforms_list2 = [c_vision.Decode(), c_vision.RandomResizeWithBBox((80, 60))] >>> image_folder_dataset_1 = image_folder_dataset_1.map(operations=transforms_list2, ... input_columns=["image"])
-
class
tinyms.vision.
RandomRotation
(degrees, resample=<Inter.NEAREST: 0>, expand=False, center=None, fill_value=0)[source]¶ Rotate the input image randomly within a specified range of degrees.
- Parameters
degrees (Union[int, float, sequence]) – Range of random rotation degrees. If degrees is a number, the range will be converted to (-degrees, degrees). If degrees is a sequence, it should be (min, max).
resample (Inter mode, optional) –
An optional resampling filter (default=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.
expand (bool, optional) – Optional expansion flag (default=False). If set to True, expand the output image to make it large enough to hold the entire rotated image. If set to False or omitted, make the output image the same size as the input. Note that the expand flag assumes rotation around the center and no translation.
center (tuple, optional) – Optional center of rotation (a 2-tuple) (default=None). Origin is the top left corner. None sets to the center of the image.
fill_value (Union[int, tuple], optional) – Optional fill color for the area outside the rotated image. If it is a 3-tuple, it is used to fill R, G, B channels respectively. If it is an integer, it is used for all RGB channels. The fill_value values must be in range [0, 255] (default=0).
Examples
>>> from mindspore.dataset.vision import Inter >>> transforms_list = [c_vision.Decode(), ... c_vision.RandomRotation(degrees=5.0, ... resample=Inter.NEAREST, ... expand=True)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomSelectSubpolicy
(policy)[source]¶ Choose a random sub-policy from a policy list to be applied on the input image.
- Parameters
policy (list(list(tuple(TensorOp, prob (float)))) – List of sub-policies to choose from. A sub-policy is a list of tuples (op, prob), where op is a TensorOp operation and prob is the probability that this op will be applied, and the prob values must be in range [0, 1]. Once a sub-policy is selected, each op within the sub-policy with be applied in sequence according to its probability.
Examples
>>> policy = [[(c_vision.RandomRotation((45, 45)), 0.5), ... (c_vision.RandomVerticalFlip(), 1), ... (c_vision.RandomColorAdjust(), 0.8)], ... [(c_vision.RandomRotation((90, 90)), 1), ... (c_vision.RandomColorAdjust(), 0.2)]] >>> image_folder_dataset = image_folder_dataset.map(operations=c_vision.RandomSelectSubpolicy(policy), ... input_columns=["image"])
-
class
tinyms.vision.
RandomSharpness
(degrees=(0.1, 1.9))[source]¶ Adjust the sharpness of the input image by a fixed or random degree. Degree of 0.0 gives a blurred image, degree of 1.0 gives the original image, and degree of 2.0 gives a sharpened image.
- Parameters
degrees (Union[list, tuple], optional) – Range of random sharpness adjustment degrees. It should be in (min, max) format. If min=max, then it is a single fixed magnitude operation (default = (0.1, 1.9)).
- Raises
TypeError – If degrees is not a list or tuple.
ValueError – If degrees is negative.
ValueError – If degrees is in (max, min) format instead of (min, max).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomSharpness(degrees=(0.2, 1.9))] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomSolarize
(threshold=(0, 255))[source]¶ Randomly selects a subrange within the specified threshold range and sets the pixel value within the subrange to (255 - pixel).
- Parameters
threshold (tuple, optional) – Range of random solarize threshold (default=(0, 255)). Threshold values should always be in (min, max) format, where min and max are integers in the range (0, 255), and min <= max. If min=max, then invert all pixel values above min(max).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomSolarize(threshold=(10,100))] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomVerticalFlip
(prob=0.5)[source]¶ Randomly flip the input image vertically with a given probability.
- Parameters
prob (float, optional) – Probability of the image being flipped (default=0.5).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomVerticalFlip(0.25)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
RandomVerticalFlipWithBBox
(prob=0.5)[source]¶ Flip the input image vertically, randomly with a given probability and adjust bounding boxes accordingly.
- Parameters
prob (float, optional) – Probability of the image being flipped (default=0.5).
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.RandomVerticalFlipWithBBox(0.20)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
Rescale
(rescale, shift)[source]¶ Rescale the input image with the given rescale and shift. This operator will rescale the input image with: output = image * rescale + shift.
Examples
>>> transforms_list = [c_vision.Decode(), c_vision.Rescale(1.0 / 255.0, -1.0)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
Resize
(size, interpolation=<Inter.BILINEAR: 2>)[source]¶ Resize the input image to the given size with a given interpolation mode.
- Parameters
size (Union[int, sequence]) – The output size of the resized image. If size is an integer, the smaller edge of the image will be resized to this value with the same image aspect ratio. If size is a sequence of length 2, it should be (height, width).
interpolation (Inter mode, optional) –
Image interpolation mode (default=Inter.LINEAR). It can be any of [Inter.LINEAR, Inter.NEAREST, Inter.BICUBIC, Inter.PILCUBIC].
Inter.LINEAR, means interpolation method is bilinear interpolation.
Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
Inter.BICUBIC, means interpolation method is bicubic interpolation.
Inter.AREA, means interpolation method is pixel area interpolation.
Inter.PILCUBIC, means interpolation method is bicubic interpolation like implemented in pillow, input should be in 3 channels format.
Examples
>>> from mindspore.dataset.vision import Inter >>> decode_op = c_vision.Decode() >>> resize_op = c_vision.Resize([100, 75], Inter.BICUBIC) >>> transforms_list = [decode_op, resize_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
ResizeWithBBox
(size, interpolation=<Inter.BILINEAR: 2>)[source]¶ Resize the input image to the given size and adjust bounding boxes accordingly.
- Parameters
size (Union[int, sequence]) – The output size of the resized image. If size is an integer, smaller edge of the image will be resized to this value with the same image aspect ratio. If size is a sequence of length 2, it should be (height, width).
interpolation (Inter mode, optional) –
Image interpolation mode (default=Inter.LINEAR). It can be any of [Inter.LINEAR, Inter.NEAREST, Inter.BICUBIC].
Inter.LINEAR, means interpolation method is bilinear interpolation.
Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
Inter.BICUBIC, means interpolation method is bicubic interpolation.
Examples
>>> from mindspore.dataset.vision import Inter >>> decode_op = c_vision.Decode() >>> bbox_op = c_vision.ResizeWithBBox(50, Inter.NEAREST) >>> transforms_list = [decode_op, bbox_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
-
class
tinyms.vision.
SoftDvppDecodeRandomCropResizeJpeg
(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), max_attempts=10)[source]¶ A combination of Crop, Decode and Resize using the simulation algorithm of Ascend series chip DVPP module.
The usage scenario is consistent with SoftDvppDecodeResizeJpeg. The input image size should be in range [32*32, 8192*8192]. The zoom-out and zoom-in multiples of the image length and width should in the range [1/32, 16]. Only images with an even resolution can be output. The output of odd resolution is not supported.
- Parameters
size (Union[int, sequence]) – The size of the output image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
scale (list, tuple, optional) – Range [min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).
ratio (list, tuple, optional) – Range [min, max) of aspect ratio to be cropped (default=(3. / 4., 4. / 3.)).
max_attempts (int, optional) – The maximum number of attempts to propose a valid crop_area (default=10). If exceeded, fall back to use center_crop instead.
Examples
>>> # decode, randomly crop and resize image, keeping aspect ratio >>> transforms_list1 = [c_vision.SoftDvppDecodeRandomCropResizeJpeg(90)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list1, ... input_columns=["image"]) >>> # decode, randomly crop and resize to landscape style >>> transforms_list2 = [c_vision.SoftDvppDecodeRandomCropResizeJpeg((80, 100))] >>> image_folder_dataset_1 = image_folder_dataset_1.map(operations=transforms_list2, ... input_columns=["image"])
-
class
tinyms.vision.
SoftDvppDecodeResizeJpeg
(size)[source]¶ Decode and resize JPEG image using the simulation algorithm of Ascend series chip DVPP module.
It is recommended to use this algorithm in the following scenarios: When training, the DVPP of the Ascend chip is not used, and the DVPP of the Ascend chip is used during inference, and the accuracy of inference is lower than the accuracy of training; and the input image size should be in range [32*32, 8192*8192]. The zoom-out and zoom-in multiples of the image length and width should in the range [1/32, 16]. Only images with an even resolution can be output. The output of odd resolution is not supported.
- Parameters
size (Union[int, sequence]) – The output size of the resized image. If size is an integer, smaller edge of the image will be resized to this value with the same image aspect ratio. If size is a sequence of length 2, it should be (height, width).
Examples
>>> # decode and resize image, keeping aspect ratio >>> transforms_list1 = [c_vision.SoftDvppDecodeResizeJpeg(70)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list1, ... input_columns=["image"]) >>> # decode and resize to portrait style >>> transforms_list2 = [c_vision.SoftDvppDecodeResizeJpeg((80, 60))] >>> image_folder_dataset_1 = image_folder_dataset_1.map(operations=transforms_list2, ... input_columns=["image"])
-
class
tinyms.vision.
UniformAugment
(transforms, num_ops=2)[source]¶ Perform randomly selected augmentation on input image.
- Parameters
transforms – List of C++ operations (Python operations are not accepted).
num_ops (int, optional) – Number of operations to be selected and applied (default=2).
Examples
>>> import mindspore.dataset.vision.py_transforms as py_vision >>> transforms_list = [c_vision.RandomHorizontalFlip(), ... c_vision.RandomVerticalFlip(), ... c_vision.RandomColorAdjust(), ... c_vision.RandomRotation(degrees=45)] >>> uni_aug_op = c_vision.UniformAugment(transforms=transforms_list, num_ops=2) >>> transforms_all = [c_vision.Decode(), c_vision.Resize(size=[224, 224]), ... uni_aug_op] >>> image_folder_dataset_1 = image_folder_dataset.map(operations=transforms_all, ... input_columns="image", ... num_parallel_workers=1)
-
class
tinyms.vision.
Compose
(transforms)[source]¶ Compose a list of transforms into a single transform.
- Parameters
transforms (list) – List of transformations to be applied.
Examples
>>> compose = c_transforms.Compose([c_vision.Decode(), c_vision.RandomCrop(512)]) >>> image_folder_dataset = image_folder_dataset.map(operations=compose)
-
class
tinyms.vision.
Concatenate
(axis=0, prepend=None, append=None)[source]¶ Tensor operation that concatenates all columns into a single tensor.
- Parameters
axis (int, optional) – Concatenate the tensors along given axis (Default=0).
prepend (numpy.array, optional) – NumPy array to be prepended to the already concatenated tensors (Default=None).
append (numpy.array, optional) – NumPy array to be appended to the already concatenated tensors (Default=None).
Examples
>>> import numpy as np >>> # concatenate string >>> prepend_tensor = np.array(["dw", "df"], dtype='S') >>> append_tensor = np.array(["dwsdf", "df"], dtype='S') >>> concatenate_op = c_transforms.Concatenate(0, prepend_tensor, append_tensor) >>> data = [["This","is","a","string"]] >>> dataset = ds.NumpySlicesDataset(data) >>> dataset = dataset.map(operations=concatenate_op)
-
class
tinyms.vision.
Duplicate
[source]¶ Duplicate the input tensor to output, only support transform one column each time.
Examples
>>> # Data before >>> # | x | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------+ >>> data = [[1,2,3]] >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["x"]) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=c_transforms.Duplicate(), ... input_columns=["x"], ... output_columns=["x", "y"], ... column_order=["x", "y"]) >>> # Data after >>> # | x | y | >>> # +---------+---------+ >>> # | [1,2,3] | [1,2,3] | >>> # +---------+---------+
-
class
tinyms.vision.
Fill
(fill_value)[source]¶ Tensor operation to fill all elements in the tensor with the specified value. The output tensor will have the same shape and type as the input tensor.
Examples
>>> import numpy as np >>> # generate a 1D integer numpy array from 0 to 4 >>> def generator_1d(): ... for i in range(5): ... yield (np.array([i]),) >>> generator_dataset = ds.GeneratorDataset(generator_1d, column_names="col1") >>> # [[0], [1], [2], [3], [4]] >>> fill_op = c_transforms.Fill(3) >>> generator_dataset = generator_dataset.map(operations=fill_op) >>> # [[3], [3], [3], [3], [3]]
-
class
tinyms.vision.
Mask
(operator, constant, dtype=mindspore.bool_)[source]¶ Mask content of the input tensor with the given predicate. Any element of the tensor that matches the predicate will be evaluated to True, otherwise False.
- Parameters
operator (Relational) – relational operators, it can be any of [Relational.EQ, Relational.NE, Relational.LT, Relational.GT, Relational.LE, Relational.GE], take Relational.EQ as example, EQ refers to equal.
constant (Union[str, int, float, bool]) – Constant to be compared to. Constant will be cast to the type of the input tensor.
dtype (mindspore.dtype, optional) – Type of the generated mask (Default mstype.bool_).
Examples
>>> from mindspore.dataset.transforms.c_transforms import Relational >>> # Data before >>> # | col | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------+ >>> data = [[1, 2, 3]] >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["col"]) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=c_transforms.Mask(Relational.EQ, 2)) >>> # Data after >>> # | col | >>> # +--------------------+ >>> # | [False,True,False] | >>> # +--------------------+
-
class
tinyms.vision.
OneHot
(num_classes)[source]¶ Tensor operation to apply one hot encoding.
- Parameters
num_classes (int) – Number of classes of objects in dataset. It should be larger than the largest label number in the dataset.
- Raises
RuntimeError – feature size is bigger than num_classes.
Examples
>>> # Assume that dataset has 10 classes, thus the label ranges from 0 to 9 >>> onehot_op = c_transforms.OneHot(num_classes=10) >>> mnist_dataset = mnist_dataset.map(operations=onehot_op, input_columns=["label"])
-
class
tinyms.vision.
PadEnd
(pad_shape, pad_value=None)[source]¶ Pad input tensor according to pad_shape, input tensor needs to have same rank.
- Parameters
pad_shape (list(int)) – List of integers representing the shape needed. Dimensions that set to None will not be padded (i.e., original dim will be used). Shorter dimensions will truncate the values.
pad_value (Union[str, bytes, int, float, bool]), optional) – Value used to pad. Default to 0 or empty string in case of tensors of strings.
Examples
>>> # Data before >>> # | col | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------| >>> data = [[1, 2, 3]] >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["col"]) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=c_transforms.PadEnd(pad_shape=[4], ... pad_value=10)) >>> # Data after >>> # | col | >>> # +------------+ >>> # | [1,2,3,10] | >>> # +------------|
-
class
tinyms.vision.
RandomApply
(transforms, prob=0.5)[source]¶ Randomly perform a series of transforms with a given probability.
- Parameters
Examples
>>> rand_apply = c_transforms.RandomApply([c_vision.RandomCrop(512)]) >>> image_folder_dataset = image_folder_dataset.map(operations=rand_apply)
-
class
tinyms.vision.
RandomChoice
(transforms)[source]¶ Randomly select one transform from a list of transforms to perform operation.
- Parameters
transforms (list) – List of transformations to be chosen from to apply.
Examples
>>> rand_choice = c_transforms.RandomChoice([c_vision.CenterCrop(50), c_vision.RandomCrop(512)]) >>> image_folder_dataset = image_folder_dataset.map(operations=rand_choice)
-
class
tinyms.vision.
Slice
(*slices)[source]¶ Slice operation to extract a tensor out using the given n slices.
The functionality of Slice is similar to NumPy’s indexing feature (Currently only rank-1 tensors are supported).
- Parameters
slices (Union[int, list[int], slice, None, Ellipsis]) –
Maximum n number of arguments to slice a tensor of rank n . One object in slices can be one of:
int
: Slice this index only along the first dimension. Negative index is supported.list(int)
: Slice these indices along the first dimension. Negative indices are supported.slice
: Slice the generated indices from the slice object along the first dimension. Similar to start:stop:step.None
: Slice the whole dimension. Similar to[:]
in Python indexing.Ellipsis
: Slice the whole dimension, same result with None.
Examples
>>> # Data before >>> # | col | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------| >>> data = [[1, 2, 3]] >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["col"]) >>> # slice indices 1 and 2 only >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=c_transforms.Slice(slice(1,3))) >>> # Data after >>> # | col | >>> # +---------+ >>> # | [2,3] | >>> # +---------|
-
class
tinyms.vision.
TypeCast
(data_type)[source]¶ Tensor operation to cast to a given MindSpore data type.
- Parameters
data_type (mindspore.dtype) – mindspore.dtype to be cast to.
Examples
>>> import numpy as np >>> from mindspore import dtype as mstype >>> >>> # Generate 1d int numpy array from 0 - 63 >>> def generator_1d(): ... for i in range(64): ... yield (np.array([i]),) >>> >>> dataset = ds.GeneratorDataset(generator_1d, column_names='col') >>> type_cast_op = c_transforms.TypeCast(mstype.int32) >>> dataset = dataset.map(operations=type_cast_op)
-
class
tinyms.vision.
Unique
[source]¶ Perform the unique operation on the input tensor, only support transform one column each time.
Return 3 tensor: unique output tensor, index tensor, count tensor.
Unique output tensor contains all the unique elements of the input tensor in the same order that they occur in the input tensor.
Index tensor that contains the index of each element of the input tensor in the unique output tensor.
Count tensor that contains the count of each element of the output tensor in the input tensor.
Note
Call batch op before calling this function.
Examples
>>> # Data before >>> # | x | >>> # +--------------------+ >>> # | [[0,1,2], [1,2,3]] | >>> # +--------------------+ >>> data = [[[0,1,2], [1,2,3]]] >>> dataset = ds.NumpySlicesDataset(data, ["x"]) >>> dataset = dataset.map(operations=c_transforms.Unique(), ... input_columns=["x"], ... output_columns=["x", "y", "z"], ... column_order=["x", "y", "z"]) >>> # Data after >>> # | x | y |z | >>> # +---------+-----------------+---------+ >>> # | [0,1,2,3] | [0,1,2,1,2,3] | [1,2,2,1] >>> # +---------+-----------------+---------+