!5971 dataset API docstring: Update transforms and vision desc and examples
Merge pull request !5971 from cathwong/ckw_api_vision_pytransforms
This commit is contained in:
commit
014af71f12
|
@ -36,6 +36,16 @@ class OneHot(cde.OneHotOp):
|
|||
|
||||
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"])
|
||||
"""
|
||||
|
||||
@check_num_classes
|
||||
|
@ -46,12 +56,17 @@ class OneHot(cde.OneHotOp):
|
|||
|
||||
class Fill(cde.FillOp):
|
||||
"""
|
||||
Tensor operation to create a tensor filled with passed scalar value.
|
||||
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.
|
||||
|
||||
Args:
|
||||
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)
|
||||
"""
|
||||
|
||||
@check_fill_value
|
||||
|
@ -64,7 +79,12 @@ class TypeCast(cde.TypeCastOp):
|
|||
Tensor operation to cast to a given MindSpore data type.
|
||||
|
||||
Args:
|
||||
data_type (mindspore.dtype): mindspore.dtype to be casted to.
|
||||
data_type (mindspore.dtype): mindspore.dtype to be cast to.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.transforms.c_transforms as c_transforms
|
||||
>>>
|
||||
>>> type_cast_op = c_transforms.TypeCast(mstype.int32)
|
||||
"""
|
||||
|
||||
@check_de_type
|
||||
|
@ -78,7 +98,7 @@ class Slice(cde.SliceOp):
|
|||
"""
|
||||
Slice operation to extract a tensor out using the given n slices.
|
||||
|
||||
The functionality of Slice is similar to NumPy indexing feature.
|
||||
The functionality of Slice is similar to NumPy's indexing feature.
|
||||
(Currently only rank-1 tensors are supported).
|
||||
|
||||
Args:
|
||||
|
@ -93,17 +113,19 @@ class Slice(cde.SliceOp):
|
|||
5. :py:obj:`Ellipses`: Slice all dimensions between the two slices. Similar to `...` in Python indexing.
|
||||
|
||||
Examples:
|
||||
>>> # Data before
|
||||
>>> # | col |
|
||||
>>> # +---------+
|
||||
>>> # | [1,2,3] |
|
||||
>>> # +---------|
|
||||
>>> data = data.map(operations=Slice(slice(1,3))) # slice indices 1 and 2 only
|
||||
>>> # Data after
|
||||
>>> # | col |
|
||||
>>> # +---------+
|
||||
>>> # | [2,3] |
|
||||
>>> # +---------|
|
||||
>>> 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] |
|
||||
>>> # +---------|
|
||||
"""
|
||||
|
||||
@check_slice_op
|
||||
|
@ -143,18 +165,20 @@ class Mask(cde.MaskOp):
|
|||
Any element of the tensor that matches the predicate will be evaluated to True, otherwise False.
|
||||
|
||||
Args:
|
||||
operator (Relational): One of the relational operator EQ, NE LT, GT, LE or GE
|
||||
constant (Union[str, int, float, bool]): constant to be compared to.
|
||||
Constant will be casted to the type of the input tensor
|
||||
dtype (mindspore.dtype, optional): type of the generated mask. Default to bool
|
||||
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] |
|
||||
>>> # +---------+
|
||||
>>> data = data.map(operations=Mask(Relational.EQ, 2))
|
||||
>>> data1 = data1.map(operations=c_transforms.Mask(Relational.EQ, 2))
|
||||
>>> # Data after
|
||||
>>> # | col1 |
|
||||
>>> # +--------------------+
|
||||
|
@ -174,18 +198,20 @@ class PadEnd(cde.PadEndOp):
|
|||
Pad input tensor according to `pad_shape`, need to have same rank.
|
||||
|
||||
Args:
|
||||
pad_shape (list(int)): list on integers representing the shape needed. Dimensions that set to `None` will
|
||||
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.
|
||||
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] |
|
||||
>>> # +---------|
|
||||
>>> data = data.map(operations=PadEnd(pad_shape=[4], pad_value=10))
|
||||
>>> data1 = data1.map(operations=c_transforms.PadEnd(pad_shape=[4], pad_value=10))
|
||||
>>> # Data after
|
||||
>>> # | col |
|
||||
>>> # +------------+
|
||||
|
@ -205,9 +231,17 @@ class Concatenate(cde.ConcatenateOp):
|
|||
Tensor operation that concatenates all columns into a single tensor.
|
||||
|
||||
Args:
|
||||
axis (int, optional): concatenate the tensors along given axis (Default=0).
|
||||
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)
|
||||
"""
|
||||
|
||||
@check_concat_type
|
||||
|
@ -224,12 +258,14 @@ class Duplicate(cde.DuplicateOp):
|
|||
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] |
|
||||
>>> # +---------+
|
||||
>>> data = data.map(operations=Duplicate(), input_columns=["x"],
|
||||
>>> data1 = data1.map(operations=c_transforms.Duplicate(), input_columns=["x"],
|
||||
>>> output_columns=["x", "y"], column_order=["x", "y"])
|
||||
>>> # Data after
|
||||
>>> # | x | y |
|
||||
|
@ -247,8 +283,11 @@ class Compose(cde.ComposeOp):
|
|||
transforms (list): List of transformations to be applied.
|
||||
|
||||
Examples:
|
||||
>>> compose = Compose([vision.Decode(), vision.RandomCrop()])
|
||||
>>> dataset = ds.map(operations=compose)
|
||||
>>> 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()])
|
||||
>>> data1 = data1.map(operations=compose)
|
||||
"""
|
||||
|
||||
@check_random_transform_ops
|
||||
|
@ -258,15 +297,18 @@ class Compose(cde.ComposeOp):
|
|||
|
||||
class RandomApply(cde.RandomApplyOp):
|
||||
"""
|
||||
Randomly performs a series of transforms with a given probability.
|
||||
Randomly perform a series of transforms with a given probability.
|
||||
|
||||
Args:
|
||||
transforms (list): List of transformations to be applied.
|
||||
prob (float, optional): The probability to apply the transformation list (default=0.5)
|
||||
|
||||
Examples:
|
||||
>>> rand_apply = RandomApply([vision.RandomCrop()])
|
||||
>>> dataset = ds.map(operations=rand_apply)
|
||||
>>> 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()])
|
||||
>>> data1 = data1.map(operations=rand_apply)
|
||||
"""
|
||||
|
||||
@check_random_transform_ops
|
||||
|
@ -282,8 +324,11 @@ class RandomChoice(cde.RandomChoiceOp):
|
|||
transforms (list): List of transformations to be chosen from to apply.
|
||||
|
||||
Examples:
|
||||
>>> rand_choice = RandomChoice([vision.CenterCrop(), vision.RandomCrop()])
|
||||
>>> dataset = ds.map(operations=rand_choice)
|
||||
>>> 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(), c_vision.RandomCrop()])
|
||||
>>> data1 = data1.map(operations=rand_choice)
|
||||
"""
|
||||
|
||||
@check_random_transform_ops
|
||||
|
|
|
@ -29,6 +29,13 @@ class OneHotOp:
|
|||
num_classes (int): Number of classes of objects in dataset. Value must be larger than 0.
|
||||
smoothing_rate (float, optional): Adjustable hyperparameter for label smoothing level.
|
||||
(Default=0.0 means no smoothing is applied.)
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.transforms as py_transforms
|
||||
>>>
|
||||
>>> transforms_list = [py_transforms.OneHotOp(num_classes=10, smoothing_rate=0.1)]
|
||||
>>> transform = py_transforms.Compose(transforms_list)
|
||||
>>> data1 = data1.map(input_columns=["label"], operations=transform())
|
||||
"""
|
||||
|
||||
@check_one_hot_op
|
||||
|
@ -65,17 +72,18 @@ class Compose:
|
|||
|
||||
Examples:
|
||||
>>> import mindspore.dataset as ds
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> import mindspore.dataset.transforms.py_transforms as py_transforms
|
||||
>>>
|
||||
>>> dataset_dir = "path/to/imagefolder_directory"
|
||||
>>> # create a dataset that reads all files in dataset_dir with 8 threads
|
||||
>>> dataset = ds.ImageFolderDataset(dataset_dir, num_parallel_workers=8)
|
||||
>>> # create a list of transformations to be applied to the image data
|
||||
>>> transform = Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomHorizontalFlip(0.5),
|
||||
>>> py_transforms.ToTensor(),
|
||||
>>> py_transforms.Normalize((0.491, 0.482, 0.447), (0.247, 0.243, 0.262)),
|
||||
>>> py_transforms.RandomErasing()])
|
||||
>>> transform = py_transform.Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomHorizontalFlip(0.5),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.Normalize((0.491, 0.482, 0.447), (0.247, 0.243, 0.262)),
|
||||
>>> py_vision.RandomErasing()])
|
||||
>>> # apply the transform to the dataset through dataset.map()
|
||||
>>> dataset = dataset.map(operations=transform, input_columns="image")
|
||||
"""
|
||||
|
|
|
@ -19,4 +19,4 @@ provide more kinds of image augmentations which is developed with Python PIL.
|
|||
"""
|
||||
from . import c_transforms
|
||||
from . import py_transforms
|
||||
from .utils import Inter, Border
|
||||
from .utils import Inter, Border, ImageBatchFormat
|
||||
|
|
|
@ -26,18 +26,19 @@ to improve their training models.
|
|||
>>> import mindspore.dataset as ds
|
||||
>>> import mindspore.dataset.transforms.c_transforms as c_transforms
|
||||
>>> import mindspore.dataset.vision.c_transforms as c_vision
|
||||
>>> from mindspore.dataset.vision.utils import Border, ImageBatchFormat, Inter
|
||||
|
||||
>>> from mindspore.dataset.vision import Border, Inter
|
||||
>>>
|
||||
>>> dataset_dir = "path/to/imagefolder_directory"
|
||||
>>> # create a dataset that reads all files in dataset_dir with 8 threads
|
||||
>>> data1 = ds.ImageFolderDataset(dataset_dir, num_parallel_workers=8)
|
||||
>>> # create a list of transformations to be applied to the image data
|
||||
>>> transforms_list = [c_vision.Decode(),
|
||||
>>> c_vision.Resize((256, 256)),
|
||||
>>> c_vision.Resize((256, 256), interpolation=Inter.LINEAR),
|
||||
>>> c_vision.RandomCrop(200, padding_mode=Border.EDGE),
|
||||
>>> c_vision.RandomRotation((0, 15)),
|
||||
>>> c_vision.Normalize((100, 115.0, 121.0), (71.0, 68.0, 70.0)),
|
||||
>>> c_vision.Normalize((100, 115.0, 121.0), (71.0, 68.0, 70.0)),
|
||||
>>> c_vision.HWC2CHW()]
|
||||
>>> onehot_op = c_transforms.OneHot(num_classes)
|
||||
>>> onehot_op = c_transforms.OneHot(num_classes=10)
|
||||
>>> # apply the transformation to the dataset through data1.map()
|
||||
>>> data1 = data1.map(operations=transforms_list, input_columns="image")
|
||||
>>> data1 = data1.map(operations=onehot_op, input_columns="label")
|
||||
|
@ -88,7 +89,9 @@ class AutoContrast(cde.AutoContrastOp):
|
|||
ignore (Union[int, sequence], optional): Pixel values to ignore (default=None).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.AutoContrast(cutoff=10.0, ignore=[10, 20])]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -116,7 +119,9 @@ class RandomSharpness(cde.RandomSharpnessOp):
|
|||
ValueError: If degrees is in (max, min) format instead of (min, max).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomSharpness(degrees=(0.2, 1.9))]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -131,7 +136,9 @@ class Equalize(cde.EqualizeOp):
|
|||
Apply histogram equalization on input image.
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.Equalize()]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -141,7 +148,9 @@ class Invert(cde.InvertOp):
|
|||
Apply invert on input image in RGB mode.
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.Invert()]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -154,7 +163,9 @@ class Decode(cde.DecodeOp):
|
|||
rgb (bool, optional): Mode of decoding input image (default=True).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomHorizontalFlip()]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -175,6 +186,10 @@ class CutMixBatch(cde.CutMixBatchOp):
|
|||
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)
|
||||
|
@ -199,7 +214,9 @@ class CutOut(cde.CutOutOp):
|
|||
num_patches (int, optional): Number of patches to be cut out of an image (default=1).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.CutOut(80, num_patches=10)]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -222,6 +239,9 @@ class MixUpBatch(cde.MixUpBatchOp):
|
|||
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)
|
||||
|
@ -246,6 +266,8 @@ class Normalize(cde.NormalizeOp):
|
|||
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]
|
||||
|
@ -271,19 +293,19 @@ class RandomAffine(cde.RandomAffineOp):
|
|||
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
|
||||
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
|
||||
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 'shear', 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])
|
||||
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 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.
|
||||
|
@ -312,6 +334,9 @@ class RandomAffine(cde.RandomAffineOp):
|
|||
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)
|
||||
|
@ -394,6 +419,8 @@ class RandomCrop(cde.RandomCropOp):
|
|||
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]
|
||||
|
@ -454,6 +481,8 @@ class RandomCropWithBBox(cde.RandomCropWithBBoxOp):
|
|||
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]
|
||||
|
@ -490,7 +519,9 @@ class RandomHorizontalFlip(cde.RandomHorizontalFlipOp):
|
|||
prob (float, optional): Probability of the image being flipped (default=0.5).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomHorizontalFlip(0.75)]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -508,7 +539,9 @@ class RandomHorizontalFlipWithBBox(cde.RandomHorizontalFlipWithBBoxOp):
|
|||
prob (float, optional): Probability of the image being flipped (default=0.5).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomHorizontalFlipWithBBox(0.70)]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -527,10 +560,12 @@ class RandomPosterize(cde.RandomPosterizeOp):
|
|||
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=[4,8]).
|
||||
magnitude operation (default=[4, 8]).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomPosterize((6,8))]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -550,7 +585,9 @@ class RandomVerticalFlip(cde.RandomVerticalFlipOp):
|
|||
prob (float, optional): Probability of the image being flipped (default=0.5).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomVerticalFlip(0.25)]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -568,7 +605,9 @@ class RandomVerticalFlipWithBBox(cde.RandomVerticalFlipWithBBoxOp):
|
|||
prob (float, optional): Probability of the image being flipped (default=0.5).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomVerticalFlipWithBBox(0.20)]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -586,16 +625,18 @@ class BoundingBoxAugment(cde.BoundingBoxAugmentOp):
|
|||
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).
|
||||
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"],
|
||||
>>> columns_order=["image", "bbox"])
|
||||
>>> column_order=["image", "bbox"])
|
||||
"""
|
||||
|
||||
@check_bounding_box_augment_cpp
|
||||
|
@ -624,6 +665,9 @@ class Resize(cde.ResizeOp):
|
|||
- 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()
|
||||
>>> resize_op = c_vision.Resize([100, 75], Inter.BICUBIC)
|
||||
>>> transforms_list = [decode_op, resize_op]
|
||||
|
@ -659,6 +703,9 @@ class ResizeWithBBox(cde.ResizeWithBBoxOp):
|
|||
- 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]
|
||||
|
@ -700,6 +747,9 @@ class RandomResizedCropWithBBox(cde.RandomCropAndResizeWithBBoxOp):
|
|||
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]
|
||||
|
@ -745,6 +795,9 @@ class RandomResizedCrop(cde.RandomCropAndResizeOp):
|
|||
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)
|
||||
|
@ -776,11 +829,13 @@ class CenterCrop(cde.CenterCropOp):
|
|||
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 = [vision.Decode(), c_vision.CenterCrop(50)]
|
||||
>>> 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 = [vision.Decode(), c_vision.CenterCrop((60, 40))]
|
||||
>>> transforms_list2 = [c_vision.Decode(), c_vision.CenterCrop((60, 40))]
|
||||
>>> data2 = data2.map(operations=transforms_list2, input_columns=["image"])
|
||||
"""
|
||||
|
||||
|
@ -800,10 +855,12 @@ class RandomColor(cde.RandomColorOp):
|
|||
Args:
|
||||
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)).
|
||||
single fixed magnitude operation (default=(0.1, 1.9)).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomColor((0.5, 2.0))]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -831,6 +888,8 @@ class RandomColorAdjust(cde.RandomColorAdjustOp):
|
|||
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]
|
||||
|
@ -887,10 +946,14 @@ class RandomRotation(cde.RandomRotationOp):
|
|||
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 int, it is used for all RGB channels.
|
||||
If it is an integer, it is used for all RGB channels.
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomRotation(degrees=5.0, expand=True)]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -920,7 +983,9 @@ class Rescale(cde.RescaleOp):
|
|||
shift (float): Shift factor.
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.Rescale(1.0 / 255.0, -1.0)]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -942,11 +1007,13 @@ class RandomResize(cde.RandomResizeOp):
|
|||
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 = [vision.Decode(), c_vision.RandomResize(50)]
|
||||
>>> 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 = [vision.Decode(), c_vision.RandomResize((40, 60))]
|
||||
>>> transforms_list2 = [c_vision.Decode(), c_vision.RandomResize((40, 60))]
|
||||
>>> data2 = data2.map(operations=transforms_list2, input_columns=["image"])
|
||||
"""
|
||||
|
||||
|
@ -970,11 +1037,13 @@ class RandomResizeWithBBox(cde.RandomResizeWithBBoxOp):
|
|||
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 = [vision.Decode(), c_vision.RandomResizeWithBBox(60)]
|
||||
>>> 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 = [vision.Decode(), c_vision.RandomResizeWithBBox((80, 60))]
|
||||
>>> transforms_list2 = [c_vision.Decode(), c_vision.RandomResizeWithBBox((80, 60))]
|
||||
>>> data2 = data2.map(operations=transforms_list2, input_columns=["image"])
|
||||
"""
|
||||
|
||||
|
@ -991,7 +1060,9 @@ class HWC2CHW(cde.ChannelSwapOp):
|
|||
Transpose the input image; shape (H, W, C) to shape (C, H, W).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomHorizontalFlip(0.75), c_vision.RandomCrop(),
|
||||
>>> import mindspore.dataset.vision.c_transforms as c_vision
|
||||
>>>
|
||||
>>> transforms_list = [c_vision.Decode(), c_vision.RandomHorizontalFlip(0.75), c_vision.RandomCrop(),
|
||||
>>> c_vision.HWC2CHW()]
|
||||
>>> data1 = data1.map(operations=transforms_list, input_columns=["image"])
|
||||
"""
|
||||
|
@ -1022,6 +1093,9 @@ class RandomCropDecodeResize(cde.RandomCropDecodeResizeOp):
|
|||
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]
|
||||
|
@ -1070,7 +1144,10 @@ class Pad(cde.PadOp):
|
|||
value of edge.
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.Pad([100, 100, 100, 100])]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
@ -1096,7 +1173,9 @@ class UniformAugment(cde.UniformAugOp):
|
|||
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(),
|
||||
|
@ -1125,10 +1204,12 @@ class RandomSelectSubpolicy(cde.RandomSelectSubpolicyOp):
|
|||
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=visions.RandomSelectSubpolicy(policy), input_columns=["image"])
|
||||
>>> data_policy = data1.map(operations=c_vision.RandomSelectSubpolicy(policy), input_columns=["image"])
|
||||
"""
|
||||
|
||||
@check_random_select_subpolicy_op
|
||||
|
@ -1156,11 +1237,13 @@ class SoftDvppDecodeResizeJpeg(cde.SoftDvppDecodeResizeJpegOp):
|
|||
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 = [vision.Decode(), c_vision.SoftDvppDecodeResizeJpeg(70)]
|
||||
>>> 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 = [vision.Decode(), c_vision.SoftDvppDecodeResizeJpeg((80, 60))]
|
||||
>>> transforms_list2 = [c_vision.Decode(), c_vision.SoftDvppDecodeResizeJpeg((80, 60))]
|
||||
>>> data2 = data2.map(operations=transforms_list2, input_columns=["image"])
|
||||
"""
|
||||
|
||||
|
@ -1194,11 +1277,13 @@ class SoftDvppDecodeRandomCropResizeJpeg(cde.SoftDvppDecodeRandomCropResizeJpegO
|
|||
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 = [vision.Decode(), c_vision.SoftDvppDecodeRandomCropResizeJpeg(90)]
|
||||
>>> 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 = [vision.Decode(), c_vision.SoftDvppDecodeRandomCropResizeJpeg((80, 100))]
|
||||
>>> transforms_list2 = [c_vision.Decode(), c_vision.SoftDvppDecodeRandomCropResizeJpeg((80, 100))]
|
||||
>>> data2 = data2.map(operations=transforms_list2, input_columns=["image"])
|
||||
"""
|
||||
|
||||
|
@ -1223,7 +1308,9 @@ class RandomSolarize(cde.RandomSolarizeOp):
|
|||
be in (min, max) format. If min=max, then it is a single fixed magnitude operation (default=(0, 255)).
|
||||
|
||||
Examples:
|
||||
>>> transforms_list = [vision.Decode(), c_vision.RandomSolarize(threshold=(10,100))]
|
||||
>>> 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"])
|
||||
"""
|
||||
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
The module vision.py_transforms is implemented based on Python PIL.
|
||||
This module provides many kinds of image augmentations. It also provides
|
||||
transferring methods between PIL image and NumPy array. For users who prefer
|
||||
Python PIL in image learning task, this module is a good tool to process image
|
||||
augmentations. Users can also self-define their own augmentations with Python
|
||||
PIL.
|
||||
Python PIL in image learning tasks, this module is a good tool to process images.
|
||||
Users can also self-define their own augmentations with Python PIL.
|
||||
"""
|
||||
import numbers
|
||||
import random
|
||||
|
@ -48,22 +47,22 @@ DE_PY_BORDER_TYPE = {Border.CONSTANT: 'constant',
|
|||
|
||||
class ToTensor:
|
||||
"""
|
||||
Convert the input NumPy image array or PIL image of shape (H,W,C) to a NumPy ndarray of shape (C,H,W).
|
||||
Convert the input NumPy image array or PIL image of shape (H, W, C) to a NumPy ndarray of shape (C, H, W).
|
||||
|
||||
Note:
|
||||
The ranges of values in height and width dimension changes from [0, 255] to [0.0, 1.0]. Type cast to output_type
|
||||
(default NumPy float 32).
|
||||
The ranges of values in height and width dimension are converted from [0, 255] to [0.0, 1.0].
|
||||
The type is cast to output_type (default NumPy float32).
|
||||
The range of channel dimension remains the same.
|
||||
|
||||
Args:
|
||||
output_type (Numpy datatype, optional): The datatype of the NumPy output (default=np.float32).
|
||||
output_type (NumPy datatype, optional): The datatype of the NumPy output (default=np.float32).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(), py_transforms.RandomHorizontalFlip(0.5),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(), py_vision.RandomHorizontalFlip(0.5),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
def __init__(self, output_type=np.float32):
|
||||
|
@ -87,16 +86,16 @@ class ToType:
|
|||
Convert the input NumPy image array to desired NumPy dtype.
|
||||
|
||||
Args:
|
||||
output_type (Numpy datatype): The datatype of the NumPy output, e.g. numpy.float32.
|
||||
output_type (NumPy datatype): The datatype of the NumPy output, e.g. numpy.float32.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>> import numpy as np
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(), py_transforms.RandomHorizontalFlip(0.5),
|
||||
>>> py_transforms.ToTensor(),
|
||||
>>> py_transforms.ToType(np.float32)])
|
||||
>>> Compose([py_vision.Decode(), py_vision.RandomHorizontalFlip(0.5),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.ToType(np.float32)])
|
||||
"""
|
||||
|
||||
def __init__(self, output_type):
|
||||
|
@ -118,6 +117,13 @@ class ToType:
|
|||
class HWC2CHW:
|
||||
"""
|
||||
Transpose a NumPy image array; shape (H, W, C) to shape (C, H, W).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.HWC2CHW()])
|
||||
"""
|
||||
|
||||
def __call__(self, img):
|
||||
|
@ -139,11 +145,11 @@ class ToPIL:
|
|||
|
||||
Examples:
|
||||
>>> # data is already decoded, but not in PIL image format
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.ToPIL(), py_transforms.RandomHorizontalFlip(0.5),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.ToPIL(), py_vision.RandomHorizontalFlip(0.5),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
def __call__(self, img):
|
||||
|
@ -164,12 +170,12 @@ class Decode:
|
|||
Decode the input image to PIL image format in RGB mode.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomHorizontalFlip(0.5),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomHorizontalFlip(0.5),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
def __call__(self, img):
|
||||
|
@ -189,22 +195,22 @@ class Normalize:
|
|||
"""
|
||||
Normalize the input NumPy image array of shape (C, H, W) with the given mean and standard deviation.
|
||||
|
||||
The values of the array need to be in range (0.0, 1.0].
|
||||
The values of the array need to be in the range (0.0, 1.0].
|
||||
|
||||
Args:
|
||||
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, 1.0].
|
||||
The mean values must be in the range (0.0, 1.0].
|
||||
std (sequence): List or tuple of standard deviations for each channel, w.r.t. channel order.
|
||||
The standard deviation values must be in range (0.0, 1.0].
|
||||
The standard deviation values must be in the range (0.0, 1.0].
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomHorizontalFlip(0.5),
|
||||
>>> py_transforms.ToTensor(),
|
||||
>>> py_transforms.Normalize((0.491, 0.482, 0.447), (0.247, 0.243, 0.262))])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomHorizontalFlip(0.5),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.Normalize((0.491, 0.482, 0.447), (0.247, 0.243, 0.262))])
|
||||
"""
|
||||
|
||||
@check_normalize_py
|
||||
|
@ -259,12 +265,12 @@ class RandomCrop:
|
|||
value of edge.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomCrop(224),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomCrop(224),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_random_crop
|
||||
|
@ -301,12 +307,12 @@ class RandomHorizontalFlip:
|
|||
prob (float, optional): Probability of the image being flipped (default=0.5).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomHorizontalFlip(0.5),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomHorizontalFlip(0.5),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_prob
|
||||
|
@ -334,12 +340,12 @@ class RandomVerticalFlip:
|
|||
prob (float, optional): Probability of the image being flipped (default=0.5).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomVerticalFlip(0.5),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomVerticalFlip(0.5),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_prob
|
||||
|
@ -371,19 +377,19 @@ class Resize:
|
|||
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.BILINEAR, means the interpolation method is bilinear interpolation.
|
||||
|
||||
- Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
|
||||
- Inter.NEAREST, means the interpolation method is nearest-neighbor interpolation.
|
||||
|
||||
- Inter.BICUBIC, means interpolation method is bicubic interpolation.
|
||||
- Inter.BICUBIC, means the interpolation method is bicubic interpolation.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.Resize(256),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.Resize(256),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_resize_interpolation
|
||||
|
@ -418,22 +424,22 @@ class RandomResizedCrop:
|
|||
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.BILINEAR, means the interpolation method is bilinear interpolation.
|
||||
|
||||
- Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
|
||||
- Inter.NEAREST, means the interpolation method is nearest-neighbor interpolation.
|
||||
|
||||
- Inter.BICUBIC, means interpolation method is bicubic interpolation.
|
||||
- Inter.BICUBIC, means the 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.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomResizedCrop(224),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomResizedCrop(224),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_random_resize_crop
|
||||
|
@ -469,12 +475,12 @@ class CenterCrop:
|
|||
If size is a sequence of length 2, it should be (height, width).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.CenterCrop(64),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.CenterCrop(64),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_crop
|
||||
|
@ -513,12 +519,12 @@ class RandomColorAdjust:
|
|||
If it is a sequence, it should be [min, max] where -0.5 <= min <= max <= 0.5.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomColorAdjust(0.4, 0.4, 0.4, 0.1),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomColorAdjust(0.4, 0.4, 0.4, 0.1),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_random_color_adjust
|
||||
|
@ -556,11 +562,11 @@ class RandomRotation:
|
|||
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 resampling method is bilinear interpolation.
|
||||
- Inter.BILINEAR, means the resampling method is bilinear interpolation.
|
||||
|
||||
- Inter.NEAREST, means resampling method is nearest-neighbor interpolation.
|
||||
- Inter.NEAREST, means the resampling method is nearest-neighbor interpolation.
|
||||
|
||||
- Inter.BICUBIC, means resampling method is bicubic interpolation.
|
||||
- Inter.BICUBIC, means the resampling 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.
|
||||
|
@ -571,15 +577,15 @@ class RandomRotation:
|
|||
fill_value (int or 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 int, it is used for all RGB channels. Default is 0.
|
||||
If it is an integer, it is used for all RGB channels. Default is 0.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomRotation(30),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomRotation(30),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_random_rotation
|
||||
|
@ -608,15 +614,15 @@ class RandomOrder:
|
|||
Perform a series of transforms to the input PIL image in a random order.
|
||||
|
||||
Args:
|
||||
transforms (list): List of the transformations to be applied.
|
||||
transforms (list): List of the transformations to apply.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomOrder(transforms_list),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomOrder(transforms_list),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_transforms_list
|
||||
|
@ -628,7 +634,7 @@ class RandomOrder:
|
|||
Call method.
|
||||
|
||||
Args:
|
||||
img (PIL image): Image to be applied transformations in a random order.
|
||||
img (PIL image): Image to apply transformations in a random order.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Transformed image.
|
||||
|
@ -641,16 +647,16 @@ class RandomApply:
|
|||
Randomly perform a series of transforms with a given probability.
|
||||
|
||||
Args:
|
||||
transforms (list): List of transformations to be applied.
|
||||
transforms (list): List of transformations to apply.
|
||||
prob (float, optional): The probability to apply the transformation list (default=0.5).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomApply(transforms_list, prob=0.6),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomApply(transforms_list, prob=0.6),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_random_apply
|
||||
|
@ -673,18 +679,18 @@ class RandomApply:
|
|||
|
||||
class RandomChoice:
|
||||
"""
|
||||
Randomly select one transform from a series of transforms and applies that on the image.
|
||||
Randomly select one transform from a series of transforms and apply that transform on the image.
|
||||
|
||||
Args:
|
||||
transforms (list): List of transformations to be chosen from to apply.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomChoice(transforms_list),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomChoice(transforms_list),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_transforms_list
|
||||
|
@ -696,7 +702,7 @@ class RandomChoice:
|
|||
Call method.
|
||||
|
||||
Args:
|
||||
img (PIL image): Image to be applied transformation.
|
||||
img (PIL image): Image to apply transformation.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Transformed image.
|
||||
|
@ -706,7 +712,7 @@ class RandomChoice:
|
|||
|
||||
class FiveCrop:
|
||||
"""
|
||||
Generate 5 cropped images (one central and four corners).
|
||||
Generate 5 cropped images (one central image and four corners images).
|
||||
|
||||
Args:
|
||||
size (int or sequence): The output size of the crop.
|
||||
|
@ -714,13 +720,13 @@ class FiveCrop:
|
|||
If size is a sequence of length 2, it should be (height, width).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.FiveCrop(size),
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.FiveCrop(size),
|
||||
>>> # 4D stack of 5 images
|
||||
>>> lambda images: numpy.stack([py_transforms.ToTensor()(image) for image in images])])
|
||||
>>> lambda images: numpy.stack([py_vision.ToTensor()(image) for image in images])])
|
||||
"""
|
||||
|
||||
@check_crop
|
||||
|
@ -743,7 +749,8 @@ class FiveCrop:
|
|||
|
||||
class TenCrop:
|
||||
"""
|
||||
Generate 10 cropped images (first 5 from FiveCrop, second 5 from their flipped version).
|
||||
Generate 10 cropped images (first 5 images from FiveCrop, second 5 images from their flipped version
|
||||
as per input flag to flip vertically or horizontally).
|
||||
|
||||
Args:
|
||||
size (Union[int, sequence]): The output size of the crop.
|
||||
|
@ -753,13 +760,13 @@ class TenCrop:
|
|||
if set to True (default=False).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.TenCrop(size),
|
||||
>>> # 4D stack of 10 images
|
||||
>>> lambda images: numpy.stack([py_transforms.ToTensor()(image) for image in images])])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.TenCrop(size),
|
||||
>>> # 4D stack of 10 images
|
||||
>>> lambda images: numpy.stack([py_vision.ToTensor()(image) for image in images])])
|
||||
"""
|
||||
|
||||
@check_ten_crop
|
||||
|
@ -793,12 +800,12 @@ class Grayscale:
|
|||
Default is 1. If set to 3, the returned image has 3 identical RGB channels.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.Grayscale(3),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.Grayscale(3),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_num_channels
|
||||
|
@ -826,12 +833,12 @@ class RandomGrayscale:
|
|||
prob (float, optional): Probability of the image being converted to grayscale (default=0.1).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomGrayscale(0.3),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomGrayscale(0.3),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_prob
|
||||
|
@ -846,7 +853,7 @@ class RandomGrayscale:
|
|||
img (PIL image): PIL image to be converted to grayscale randomly.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Randomly grayscale image, same number of channels as input image.
|
||||
img (PIL image), Randomly apply grayscale to image, same number of channels as the input image.
|
||||
If input image has 1 channel, the output grayscale image is 1 channel.
|
||||
If input image has 3 channels, the output image has 3 identical grayscale channels.
|
||||
"""
|
||||
|
@ -866,16 +873,16 @@ class Pad:
|
|||
|
||||
Args:
|
||||
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 a single number is provided, pad all borders with this value.
|
||||
If a tuple or list of 2 values is provided, pad the left and top
|
||||
with the first value and the 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): Filling value (default=0). The pixel intensity
|
||||
of the borders if the padding_mode is Border.CONSTANT.
|
||||
pad the left, top, right and bottom respectively.
|
||||
fill_value (Union[int, tuple], optional): Filling value for 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).
|
||||
Can be any of [Border.CONSTANT, Border.EDGE, Border.REFLECT, Border.SYMMETRIC].
|
||||
It can be any of [Border.CONSTANT, Border.EDGE, Border.REFLECT, Border.SYMMETRIC].
|
||||
|
||||
- Border.CONSTANT, means it fills the border with constant values.
|
||||
|
||||
|
@ -888,13 +895,13 @@ class Pad:
|
|||
value of edge.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> # adds 10 pixels (default black) to each side of the border of the image
|
||||
>>> py_transforms.Pad(padding=10),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> py_vision.Pad(padding=10),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_pad
|
||||
|
@ -923,24 +930,24 @@ class RandomPerspective:
|
|||
Randomly apply perspective transformation to the input PIL image with a given probability.
|
||||
|
||||
Args:
|
||||
distortion_scale (float, optional): The scale of distortion, float between 0 and 1 (default=0.5).
|
||||
distortion_scale (float, optional): The scale of distortion, a float value between 0 and 1 (default=0.5).
|
||||
prob (float, optional): Probability of the image being applied perspective transformation (default=0.5).
|
||||
interpolation (Inter mode, optional): Image interpolation mode (default=Inter.BICUBIC).
|
||||
It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC].
|
||||
|
||||
- Inter.BILINEAR, means interpolation method is bilinear interpolation.
|
||||
- Inter.BILINEAR, means the interpolation method is bilinear interpolation.
|
||||
|
||||
- Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
|
||||
- Inter.NEAREST, means the interpolation method is nearest-neighbor interpolation.
|
||||
|
||||
- Inter.BICUBIC, means interpolation method is bicubic interpolation.
|
||||
- Inter.BICUBIC, means the interpolation method is bicubic interpolation.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomPerspective(prob=0.1),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomPerspective(prob=0.1),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_random_perspective
|
||||
|
@ -954,7 +961,7 @@ class RandomPerspective:
|
|||
Call method.
|
||||
|
||||
Args:
|
||||
img (PIL image): PIL image to be applied perspective transformation randomly.
|
||||
img (PIL image): PIL image to apply perspective transformation randomly.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Image after being perspectively transformed randomly.
|
||||
|
@ -979,21 +986,21 @@ class RandomErasing:
|
|||
original image (default=(0.02, 0.33)).
|
||||
ratio (sequence of floats, optional): Range of the aspect ratio of the erase
|
||||
area (default=(0.3, 3.3)).
|
||||
value (Union[int, sequence]): Erasing value (default=0).
|
||||
If value is a single int, it is applied to all pixels to be erases.
|
||||
value (Union[int, sequence, string]): Erasing value (default=0).
|
||||
If value is a single intieger, it is applied to all pixels to be erased.
|
||||
If value is a sequence of length 3, it is applied to R, G, B channels respectively.
|
||||
If value is a str 'random', the erase value will be obtained from a standard normal distribution.
|
||||
inplace (bool, optional): Apply this transform inplace (default=False).
|
||||
If value is a string 'random', the erase value will be obtained from a standard normal distribution.
|
||||
inplace (bool, optional): Apply this transform in-place (default=False).
|
||||
max_attempts (int, optional): The maximum number of attempts to propose a valid
|
||||
erase_area (default=10). If exceeded, return the original image.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.ToTensor(),
|
||||
>>> py_transforms.RandomErasing(value='random')])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.RandomErasing(value='random')])
|
||||
"""
|
||||
|
||||
@check_random_erasing
|
||||
|
@ -1035,12 +1042,12 @@ class Cutout:
|
|||
num_patches (int, optional): Number of patches to be cut out of an image (default=1).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.ToTensor(),
|
||||
>>> py_transforms.Cutout(80)])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.Cutout(80)])
|
||||
"""
|
||||
|
||||
@check_cutout
|
||||
|
@ -1074,23 +1081,23 @@ class Cutout:
|
|||
class LinearTransformation:
|
||||
"""
|
||||
Apply linear transformation to the input NumPy image array, given a square transformation matrix and
|
||||
a mean_vector.
|
||||
a mean vector.
|
||||
|
||||
The transformation first flattens the input array and subtract mean_vector from it, then computes the
|
||||
dot product with the transformation matrix, and reshapes it back to its original shape.
|
||||
The transformation first flattens the input array and subtracts the mean vector from it. It then computes
|
||||
the dot product with the transformation matrix, and reshapes it back to its original shape.
|
||||
|
||||
Args:
|
||||
transformation_matrix (numpy.ndarray): a square transformation matrix of shape (D, D), D = C x H x W.
|
||||
mean_vector (numpy.ndarray): a NumPy ndarray of shape (D,) where D = C x H x W.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.Resize(256),
|
||||
>>> py_transforms.ToTensor(),
|
||||
>>> py_transforms.LinearTransformation(transformation_matrix, mean_vector)])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.Resize(256),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.LinearTransformation(transformation_matrix, mean_vector)])
|
||||
"""
|
||||
|
||||
@check_linear_transform
|
||||
|
@ -1121,17 +1128,17 @@ class RandomAffine:
|
|||
If degrees is a sequence, it should be (min, max).
|
||||
translate (sequence, optional): Sequence (tx, ty) of maximum translation in
|
||||
x(horizontal) and y(vertical) directions (default=None).
|
||||
The horizontal and vertical shift is selected randomly from the range:
|
||||
The horizontal shift and vertical shift are selected randomly from the range:
|
||||
(-tx*width, tx*width) and (-ty*height, ty*height), respectively.
|
||||
If None, no translations gets applied.
|
||||
If None, no translations are applied.
|
||||
scale (sequence, optional): Scaling factor interval (default=None, original scale is used).
|
||||
shear (Union[int, float, sequence], optional): Range of shear factor (default=None).
|
||||
If a number 'shear', 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.
|
||||
If shear is an integer, then a shear parallel to the X axis in the range of (-shear, +shear) is applied.
|
||||
If shear is a tuple or list of size 2, then a shear parallel to the X axis in the range of
|
||||
(shear[0], shear[1]) is applied.
|
||||
If shear is a tuple of list of size 4, then a shear parallel to X axis in the range of
|
||||
(shear[0], shear[1]) and a shear parallel to Y axis in the range of (shear[2], shear[3]) is applied.
|
||||
If shear is None, no shear is applied.
|
||||
resample (Inter mode, optional): An optional resampling filter (default=Inter.NEAREST).
|
||||
If omitted, or if the image has mode "1" or "P", it is set to be Inter.NEAREST.
|
||||
It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC].
|
||||
|
@ -1142,8 +1149,9 @@ class RandomAffine:
|
|||
|
||||
- Inter.BICUBIC, means resample method is bicubic interpolation.
|
||||
|
||||
fill_value (Union[tuple, 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].
|
||||
fill_value (Union[tuple, int], optional): Optional filling value to fill the area outside the transform
|
||||
in the output image. There must be three elements in the tuple and the value of a single element is
|
||||
within the range [0, 255].
|
||||
Used only in Pillow versions > 5.0.0 (default=0, filling is performed).
|
||||
|
||||
Raises:
|
||||
|
@ -1159,12 +1167,12 @@ class RandomAffine:
|
|||
TypeError: If fill_value is not a single integer or a 3-tuple.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomAffine(degrees=15, translate=(0.1, 0.1), scale=(0.9, 1.1)),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomAffine(degrees=15, translate=(0.1, 0.1), scale=(0.9, 1.1)),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_random_affine
|
||||
|
@ -1195,7 +1203,7 @@ class RandomAffine:
|
|||
Call method.
|
||||
|
||||
Args:
|
||||
img (PIL image): Image to be applied affine transformation.
|
||||
img (PIL image): Image to apply affine transformation.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Randomly affine transformed image.
|
||||
|
@ -1212,12 +1220,22 @@ class RandomAffine:
|
|||
|
||||
class MixUp:
|
||||
"""
|
||||
Apply mix up transformation to the input image and label, make one input data combined with others.
|
||||
Apply mix up transformation to the input image and label. Make one input data combined with others.
|
||||
|
||||
Args:
|
||||
batch_size (int): the batch size of dataset.
|
||||
alpha (float): the mix up rate.
|
||||
is_single (bool): for deciding using single batch or muti batch mix up transformation.
|
||||
batch_size (int): Batch size of dataset.
|
||||
alpha (float): Mix up rate.
|
||||
is_single (bool): Identify if single batch or multi-batch mix up transformation is to be used
|
||||
(Default=True, which is single batch).
|
||||
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>>
|
||||
>>> # Setup multi-batch mixup transformation
|
||||
>>> transform = [py_vision.MixUp(batch_size=16, alpha=0.2, is_single=False)]
|
||||
>>> # Apply the transform to the dataset through dataset.map()
|
||||
>>> dataset = dataset.map(input_columns="image", operations=transform())
|
||||
"""
|
||||
|
||||
@check_mix_up
|
||||
|
@ -1234,12 +1252,12 @@ class MixUp:
|
|||
Call method.
|
||||
|
||||
Args:
|
||||
image (numpy.ndarray): NumPy image to be applied mix up transformation.
|
||||
label(numpy.ndarray): NumPy label to be applied mix up transformation.
|
||||
image (numpy.ndarray): NumPy image to apply mix up transformation.
|
||||
label(numpy.ndarray): NumPy label to apply mix up transformation.
|
||||
|
||||
Returns:
|
||||
image (numpy.ndarray): NumPy image after being applied mix up transformation.
|
||||
label(numpy.ndarray): NumPy label after being applied mix up transformation.
|
||||
image (numpy.ndarray): NumPy image after applying mix up transformation.
|
||||
label(numpy.ndarray): NumPy label after applying mix up transformation.
|
||||
"""
|
||||
if self.is_single:
|
||||
return util.mix_up_single(self.batch_size, image, label, self.alpha)
|
||||
|
@ -1248,11 +1266,20 @@ class MixUp:
|
|||
|
||||
class RgbToHsv:
|
||||
"""
|
||||
Convert a NumPy RGB image or one batch NumPy RGB images to HSV images.
|
||||
Convert a NumPy RGB image or a batch of NumPy RGB images to HSV images.
|
||||
|
||||
Args:
|
||||
is_hwc (bool): The flag of image shape, (H, W, C) or (N, H, W, C) if True
|
||||
and (C, H, W) or (N, C, H, W) if False (default=False).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.CenterCrop(20),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.RgbToHsv()])
|
||||
"""
|
||||
|
||||
def __init__(self, is_hwc=False):
|
||||
|
@ -1279,6 +1306,15 @@ class HsvToRgb:
|
|||
Args:
|
||||
is_hwc (bool): The flag of image shape, (H, W, C) or (N, H, W, C) if True
|
||||
and (C, H, W) or (N, C, H, W) if False (default=False).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.CenterCrop(20),
|
||||
>>> py_vision.ToTensor(),
|
||||
>>> py_vision.HsvToRgb()])
|
||||
"""
|
||||
|
||||
def __init__(self, is_hwc=False):
|
||||
|
@ -1307,12 +1343,12 @@ class RandomColor:
|
|||
It should be in (min, max) format (default=(0.1,1.9)).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomColor((0.5,1.5)),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomColor((0.5, 2.0)),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_positive_degrees
|
||||
|
@ -1342,13 +1378,12 @@ class RandomSharpness:
|
|||
It should be in (min, max) format (default=(0.1,1.9)).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.RandomSharpness((0.5,1.5)),
|
||||
>>> py_transforms.ToTensor()])
|
||||
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.RandomSharpness((0.5, 1.5)),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_positive_degrees
|
||||
|
@ -1378,12 +1413,12 @@ class AutoContrast:
|
|||
ignore (Union[int, sequence], optional): Pixel values to ignore (default=None).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.AutoContrast(),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.AutoContrast(),
|
||||
>>> py_vision.ToTensor()])
|
||||
|
||||
"""
|
||||
|
||||
|
@ -1411,12 +1446,12 @@ class Invert:
|
|||
Invert colors of input PIL image.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.Invert(),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.Invert(),
|
||||
>>> py_vision.ToTensor()])
|
||||
|
||||
"""
|
||||
|
||||
|
@ -1439,12 +1474,12 @@ class Equalize:
|
|||
Equalize the histogram of input PIL image.
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.Equalize(),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.Equalize(),
|
||||
>>> py_vision.ToTensor()])
|
||||
|
||||
"""
|
||||
|
||||
|
@ -1465,8 +1500,9 @@ class Equalize:
|
|||
class UniformAugment:
|
||||
"""
|
||||
Uniformly select and apply a number of transforms sequentially from
|
||||
a list of transforms. Randomly assigns a probability to each transform for
|
||||
each image to decide whether apply it or not.
|
||||
a list of transforms. Randomly assign a probability to each transform for
|
||||
each image to decide whether to apply the transform or not.
|
||||
|
||||
All the transforms in transform list must have the same input/output data type.
|
||||
|
||||
Args:
|
||||
|
@ -1474,16 +1510,16 @@ class UniformAugment:
|
|||
num_ops (int, optional): number of transforms to sequentially apply (default=2).
|
||||
|
||||
Examples:
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_transforms
|
||||
>>> import mindspore.dataset.vision.py_transforms as py_vision
|
||||
>>> from mindspore.dataset.transforms.py_transforms import Compose
|
||||
>>>
|
||||
>>> transforms_list = [py_transforms.CenterCrop(64),
|
||||
>>> py_transforms.RandomColor(),
|
||||
>>> py_transforms.RandomSharpness(),
|
||||
>>> py_transforms.RandomRotation(30)]
|
||||
>>> Compose([py_transforms.Decode(),
|
||||
>>> py_transforms.UniformAugment(transforms_list),
|
||||
>>> py_transforms.ToTensor()])
|
||||
>>> transforms_list = [py_vision.CenterCrop(64),
|
||||
>>> py_vision.RandomColor(),
|
||||
>>> py_vision.RandomSharpness(),
|
||||
>>> py_vision.RandomRotation(30)]
|
||||
>>> Compose([py_vision.Decode(),
|
||||
>>> py_vision.UniformAugment(transforms_list),
|
||||
>>> py_vision.ToTensor()])
|
||||
"""
|
||||
|
||||
@check_uniform_augment_py
|
||||
|
@ -1496,7 +1532,7 @@ class UniformAugment:
|
|||
Call method.
|
||||
|
||||
Args:
|
||||
img (PIL image): Image to be applied transformation.
|
||||
img (PIL image): Image to apply transformation.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Transformed image.
|
||||
|
|
|
@ -580,7 +580,7 @@ def rotate(img, angle, resample, expand, center, fill_value):
|
|||
Origin is the top left corner.
|
||||
fill_value (Union[int, tuple]): Optional fill color for the area outside the rotated image.
|
||||
If it is a 3-tuple, it is used for R, G, B channels respectively.
|
||||
If it is an int, it is used for all RGB channels.
|
||||
If it is an integer, it is used for all RGB channels.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Rotated image.
|
||||
|
@ -677,7 +677,7 @@ def random_rotation(img, degrees, resample, expand, center, fill_value):
|
|||
Origin is the top left corner.
|
||||
fill_value (Union[int, tuple]): Optional fill color for the area outside the rotated image.
|
||||
If it is a 3-tuple, it is used for R, G, B channels respectively.
|
||||
If it is an int, it is used for all RGB channels.
|
||||
If it is an integer, it is used for all RGB channels.
|
||||
|
||||
Returns:
|
||||
img (PIL image), Rotated image.
|
||||
|
@ -1108,7 +1108,7 @@ def random_affine(img, angle, translations, scale, shear, resample, fill_value=0
|
|||
angle (Union[int, float]): Rotation angle in degrees, clockwise.
|
||||
translations (sequence): Translations in horizontal and vertical axis.
|
||||
scale (float): Scale parameter, a single number.
|
||||
shear (Union[float, sequence]): Shear amount parallel to x and y axis.
|
||||
shear (Union[float, sequence]): Shear amount parallel to X axis and Y axis.
|
||||
resample (Union[Inter.NEAREST, Inter.BILINEAR, Inter.BICUBIC], optional): An optional resampling filter.
|
||||
fill_value (Union[tuple int], optional): Optional fill_value to fill the area outside the transform
|
||||
in the output image. Used only in Pillow versions > 5.0.0.
|
||||
|
@ -1294,7 +1294,7 @@ def rgb_to_hsvs(np_rgb_imgs, is_hwc):
|
|||
shape_size = len(np_rgb_imgs.shape)
|
||||
|
||||
if not shape_size in (3, 4):
|
||||
raise TypeError('img shape should be (H, W, C)/(N, H, W, C)/(C,H,W)/(N,C,H,W). \
|
||||
raise TypeError('img shape should be (H, W, C)/(N, H, W, C)/(C ,H, W)/(N, C, H, W). \
|
||||
Got {}'.format(np_rgb_imgs.shape))
|
||||
|
||||
if shape_size == 3:
|
||||
|
@ -1362,7 +1362,7 @@ def hsv_to_rgbs(np_hsv_imgs, is_hwc):
|
|||
shape_size = len(np_hsv_imgs.shape)
|
||||
|
||||
if not shape_size in (3, 4):
|
||||
raise TypeError('img shape should be (H, W, C)/(N, H, W, C)/(C,H,W)/(N,C,H,W). \
|
||||
raise TypeError('img shape should be (H, W, C)/(N, H, W, C)/(C, H, W)/(N, C, H, W). \
|
||||
Got {}'.format(np_hsv_imgs.shape))
|
||||
|
||||
if shape_size == 3:
|
||||
|
|
Loading…
Reference in New Issue