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
  • pred_res (dict) – The predcition result from tinyms.serving.predict method.

  • labels (list) – The labels should be input manually with a list of string. This argument is required for distinguishing the color from different classes.

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]

An enumeration.

class tinyms.vision.Border[source]

An enumeration.

class tinyms.vision.ImageBatchFormat[source]

An enumeration.

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

  • xmin, ymax, xmax] ([ymin,) –

  • 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].

tinyms.vision.coco_eval(pred_data, anno_file)[source]

Calculate mAP of predicted bboxes.

class tinyms.vision.MnistTransform[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('example.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[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('example.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[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('example.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[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('example.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
  • cifar10_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.CycleGanDatasetTransform[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('example.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.

Parameters
  • cutoff (float, optional) – Percent of pixels to cut off from the histogram (default=0.0).

  • ignore (Union[int, sequence], optional) – Pixel values to ignore (default=None).

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.AutoContrast(cutoff=10.0, ignore=[10, 20])]
>>> data1 = data1.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 function 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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> # 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
>>> data3 = data3.map(operations=[bbox_aug_op],
>>>                   input_columns=["image", "bbox"],
>>>                   output_columns=["image", "bbox"],
>>>                   column_order=["image", "bbox"])
class tinyms.vision.CenterCrop(size)[source]

Crops the input image at the center to the given size.

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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> # crop image to a square
>>> transforms_list1 = [c_vision.Decode(), c_vision.CenterCrop(50)]
>>> data1 = data1.map(operations=transforms_list1, input_columns=["image"])
>>> # crop image to portrait style
>>> transforms_list2 = [c_vision.Decode(), c_vision.CenterCrop((60, 40))]
>>> data2 = data2.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 batch before calling this function.

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

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.vision import ImageBatchFormat
>>>
>>> onehot_op = c_transforms.OneHot(num_classes=10)
>>> data1 = data1.map(operations=onehot_op, input_columns=["label"])
>>> cutmix_batch_op = c_vision.CutMixBatch(ImageBatchFormat.NHWC, 1.0, 0.5)
>>> data1 = data1.batch(5)
>>> data1 = data1.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 NumPy image array.

Parameters
  • length (int) – The side length of each square patch.

  • num_patches (int, optional) – Number of patches to be cut out of an image (default=1).

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.CutOut(80, num_patches=10)]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.Decode(rgb=True)[source]

Decode the input image in RGB mode.

Parameters

rgb (bool, optional) – Mode of decoding input image (default=True). If True means format of decoded image is RGB else BGR(deprecated).

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlip()]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.Equalize[source]

Apply histogram equalization on input image.

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.Equalize()]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.Grayscale(num_output_channels=1)[source]

Convert the input PIL image to grayscale image.

Parameters

num_output_channels (int) – Number of channels of the output grayscale image (1 or 3). Default is 1. If set to 3, the returned image has 3 identical RGB channels.

Examples

>>> import mindspore.dataset.vision.py_transforms as py_vision
>>> from mindspore.dataset.transforms.py_transforms import Compose
>>>
>>> Compose([py_vision.Decode(),
>>>          py_vision.Grayscale(3),
>>>          py_vision.ToTensor()])
class tinyms.vision.HWC2CHW[source]

Transpose the input image; shape (H, W, C) to shape (C, H, W).

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlip(0.75), c_vision.RandomCrop(512),
>>>     c_vision.HWC2CHW()]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.Invert[source]

Apply invert on input image in RGB mode.

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.Invert()]
>>> data1 = data1.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. Note that you need to make labels into one-hot format and batch before calling this function.

Parameters

alpha (float, optional) – Hyperparameter of beta distribution (default = 1.0).

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> onehot_op = c_transforms.OneHot(num_classes=10)
>>> data1 = data1.map(operations=onehot_op, input_columns=["label"])
>>> mixup_batch_op = c_vision.MixUpBatch(alpha=0.9)
>>> data1 = data1.batch(5)
>>> data1 = data1.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.

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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> 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]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.Pad(padding, fill_value=0, padding_mode=<Border.CONSTANT: 'constant'>)[source]

Pads 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 list 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 (default=0). If it is an integer, it is used for all RGB channels. If it is a 3-tuple, it is used to fill R, G, B channels respectively. The fill_value values must be in range [0, 255].

  • 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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.vision import Border
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.Pad([100, 100, 100, 100])]
>>> data1 = data1.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). 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 (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]. 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 -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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.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]
>>> data1 = data1.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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomColor((0.5, 2.0))]
>>> data1 = data1.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, 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, 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, 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, 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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> 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]
>>> data1 = data1.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.

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 firstly with padding values. If a single number is provided, pad all borders with this value. If a tuple or list 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 if the padding_mode is Border.CONSTANT (default=0). If it is a 3-tuple, it is used to fill R, G, B channels respectively.

  • 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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> 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]
>>> data1 = data1.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]

Equivalent to RandomResizedCrop, but crops before decodes.

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 (tuple, optional) – Range [min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).

  • ratio (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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.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]
>>> data1 = data1.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 list 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 if the padding_mode is Border.CONSTANT (default=0). If it is a 3-tuple, it is used to fill R, G, B channels respectively.

  • 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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> decode_op = c_vision.Decode()
>>> random_crop_with_bbox_op = c_vision.RandomCrop([512, 512], [200, 200, 200, 200])
>>> transforms_list = [decode_op, random_crop_with_bbox_op]
>>> data3 = data3.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.RandomHorizontalFlip(prob=0.5)[source]

Flip the input image horizontally, randomly with a given probability.

Parameters

prob (float, optional) – Probability of the image being flipped (default=0.5).

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlip(0.75)]
>>> data1 = data1.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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlipWithBBox(0.70)]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.RandomPosterize(bits=(8, 8))[source]

Reduce the number of bits for each color channel.

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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomPosterize((6, 8))]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.RandomResize(size)[source]

Tensor operation to 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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> # randomly resize image, keeping aspect ratio
>>> transforms_list1 = [c_vision.Decode(), c_vision.RandomResize(50)]
>>> data1 = data1.map(operations=transforms_list1, input_columns=["image"])
>>> # randomly resize image to landscape style
>>> transforms_list2 = [c_vision.Decode(), c_vision.RandomResize((40, 60))]
>>> data2 = data2.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.

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 (tuple, optional) – Range [min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).

  • ratio (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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.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]
>>> data1 = data1.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 (tuple, optional) – Range (min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).

  • ratio (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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.vision import Inter
>>>
>>> decode_op = c_vision.Decode()
>>> bbox_op = c_vision.RandomResizedCropWithBBox(size=50, interpolation=Inter.NEAREST)
>>> transforms_list = [decode_op, bbox_op]
>>> data3 = data3.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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> # randomly resize image with bounding boxes, keeping aspect ratio
>>> transforms_list1 = [c_vision.Decode(), c_vision.RandomResizeWithBBox(60)]
>>> data1 = data1.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))]
>>> data2 = data2.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 by a random angle.

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). 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.

  • 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 (default=0). If it is a 3-tuple, it is used for R, G, B channels respectively. If it is an integer, it is used for all RGB channels.

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.vision import Inter
>>>
>>> transforms_list = [c_vision.Decode(),
>>>                    c_vision.RandomRotation(degrees=5.0, resample=Inter.NEAREST, expand=True)]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.RandomSelectSubpolicy(policy)[source]

Choose a random sub-policy from a list to be applied on the input image. 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. Once a sub-policy is selected, each op within the subpolicy with be applied in sequence according to its probability.

Parameters

policy (list(list(tuple(TensorOp,float))) – List of sub-policies to choose from.

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> 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)]]
>>> data_policy = data1.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 (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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomSharpness(degrees=(0.2, 1.9))]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.RandomSolarize(threshold=(0, 255))[source]

Invert all pixel values above a threshold.

Parameters

threshold (tuple, optional) – Range of random solarize threshold. Threshold values should always be in the range (0, 255), include at least one integer value in the given range and be in (min, max) format. If min=max, then it is a single fixed magnitude operation (default=(0, 255)).

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomSolarize(threshold=(10,100))]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.RandomVerticalFlip(prob=0.5)[source]

Flip the input image vertically, randomly with a given probability.

Parameters

prob (float, optional) – Probability of the image being flipped (default=0.5).

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomVerticalFlip(0.25)]
>>> data1 = data1.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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.RandomVerticalFlipWithBBox(0.20)]
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
class tinyms.vision.Rescale(rescale, shift)[source]

Tensor operation to rescale the input image.

Parameters
  • rescale (float) – Rescale factor.

  • shift (float) – Shift factor.

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> transforms_list = [c_vision.Decode(), c_vision.Rescale(1.0 / 255.0, -1.0)]
>>> data1 = data1.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.

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.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.

Examples

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.vision import Inter
>>>
>>> decode_op = c_vision.Decode()
>>> resize_op = c_vision.Resize([100, 75], Inter.BICUBIC)
>>> transforms_list = [decode_op, resize_op]
>>> data1 = data1.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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>> from mindspore.dataset.transforms.vision import Inter
>>>
>>> decode_op = c_vision.Decode()
>>> bbox_op = c_vision.ResizeWithBBox(50, Inter.NEAREST)
>>> transforms_list = [decode_op, bbox_op]
>>> data3 = data3.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]

Tensor operation to decode, random crop and resize JPEG image 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 (tuple, optional) – Range [min, max) of respective size of the original size to be cropped (default=(0.08, 1.0)).

  • ratio (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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> # decode, randomly crop and resize image, keeping aspect ratio
>>> transforms_list1 = [c_vision.Decode(), c_vision.SoftDvppDecodeRandomCropResizeJpeg(90)]
>>> data1 = data1.map(operations=transforms_list1, input_columns=["image"])
>>> # decode, randomly crop and resize to landscape style
>>> transforms_list2 = [c_vision.Decode(), c_vision.SoftDvppDecodeRandomCropResizeJpeg((80, 100))]
>>> data2 = data2.map(operations=transforms_list2, input_columns=["image"])
class tinyms.vision.SoftDvppDecodeResizeJpeg(size)[source]

Tensor operation to 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

>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> # decode and resize image, keeping aspect ratio
>>> transforms_list1 = [c_vision.Decode(), c_vision.SoftDvppDecodeResizeJpeg(70)]
>>> data1 = data1.map(operations=transforms_list1, input_columns=["image"])
>>> # decode and resize to portrait style
>>> transforms_list2 = [c_vision.Decode(), c_vision.SoftDvppDecodeResizeJpeg((80, 60))]
>>> data2 = data2.map(operations=transforms_list2, input_columns=["image"])
class tinyms.vision.UniformAugment(transforms, num_ops=2)[source]

Tensor operation to perform randomly selected augmentation.

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.c_transforms as c_vision
>>> 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, py_vision.ToTensor()]
>>> data_aug = data1.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

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> compose = c_transforms.Compose([c_vision.Decode(), c_vision.RandomCrop(512)])
>>> data1 = data1.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 mindspore.dataset.transforms.c_transforms as c_transforms
>>>
>>> # 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)
class tinyms.vision.Duplicate[source]

Duplicate the input tensor to a new output tensor. The input tensor is carried over to the output list.

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>>
>>> # Data before
>>> # |  x      |
>>> # +---------+
>>> # | [1,2,3] |
>>> # +---------+
>>> data1 = data1.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 create a tensor filled with input scalar value. The output tensor will have the same shape and type as the input tensor.

Parameters

fill_value (Union[str, bytes, int, float, bool])) – scalar value to fill created tensor with.

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>>
>>> fill_op = c_transforms.Fill(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) – One of the relational operators EQ, NE LT, GT, LE or GE

  • 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 to bool).

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>>
>>> # Data before
>>> # |  col1   |
>>> # +---------+
>>> # | [1,2,3] |
>>> # +---------+
>>> data1 = data1.map(operations=c_transforms.Mask(Relational.EQ, 2))
>>> # Data after
>>> # |       col1         |
>>> # +--------------------+
>>> # | [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 the label. It should be larger than the largest label number in the dataset.

Raises

RuntimeError – feature size is bigger than num_classes.

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> onehot_op = c_transforms.OneHot(num_classes=10)
>>> data1 = data1.map(operations=onehot_op, input_columns=["label"])
>>> mixup_batch_op = c_vision.MixUpBatch(alpha=0.8)
>>> data1 = data1.batch(4)
>>> data1 = data1.map(operations=mixup_batch_op, input_columns=["image", "label"])
class tinyms.vision.PadEnd(pad_shape, pad_value=None)[source]

Pad input tensor according to pad_shape, need 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

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>>
>>> # Data before
>>> # |   col   |
>>> # +---------+
>>> # | [1,2,3] |
>>> # +---------|
>>> data1 = data1.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
  • transforms (list) – List of transformations to be applied.

  • prob (float, optional) – The probability to apply the transformation list (default=0.5)

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> rand_apply = c_transforms.RandomApply([c_vision.RandomCrop(512)])
>>> data1 = data1.map(operations=rand_apply)
class tinyms.vision.RandomChoice(transforms)[source]

Randomly selects one transform from a list of transforms to perform operation.

Parameters

transforms (list) – List of transformations to be chosen from to apply.

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>> import mindspore.dataset.vision.c_transforms as c_vision
>>>
>>> rand_choice = c_transforms.RandomChoice([c_vision.CenterCrop(50), c_vision.RandomCrop(512)])
>>> data1 = data1.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, Ellipses]) –

Maximum n number of arguments to slice a tensor of rank n. One object in slices can be one of:

  1. int: Slice this index only along the first dimension. Negative index is supported.

  2. list(int): Slice these indices along the first dimension. Negative indices are supported.

  3. slice: Slice the generated indices from the slice object along the first dimension. Similar to start:stop:step.

  4. None: Slice the whole dimension. Similar to : in Python indexing.

  5. Ellipses: Slice the whole dimension. Similar to : in Python indexing.

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>>
>>> # Data before
>>> # |   col   |
>>> # +---------+
>>> # | [1,2,3] |
>>> # +---------|
>>> data1 = data1.map(operations=c_transforms.Slice(slice(1,3))) # slice indices 1 and 2 only
>>> # 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 mindspore.dataset.transforms.c_transforms as c_transforms
>>> import mindspore.common.dtype as mstype
>>>
>>> type_cast_op = c_transforms.TypeCast(mstype.int32)
class tinyms.vision.Unique[source]

Return an output tensor containing all the unique elements of the input tensor in the same order that they occur in the input tensor.

Also return an index tensor that contains the index of each element of the input tensor in the Unique output tensor.

Finally, return a count tensor that constains the count of each element of the output tensor in the input tensor.

Note

Call batch op before calling this function.

Examples

>>> import mindspore.dataset.transforms.c_transforms as c_transforms
>>>
>>> # Data before
>>> # |  x                 |
>>> # +--------------------+
>>> # | [[0,1,2], [1,2,3]] |
>>> # +--------------------+
>>> data1 = data1.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]
>>> # +---------+-----------------+---------+