mindspore.dataset.transforms
mindspore.dataset.transforms.c_transforms
This module c_transforms provides common operations, including OneHotOp and TypeCast.
- class mindspore.dataset.transforms.c_transforms.Compose(transforms)[source]
Compose a list of transforms into a single transform.
- Parameters
transforms (list) – List of transformations to be applied.
Examples
>>> compose = Compose([vision.Decode(), vision.RandomCrop()]) >>> dataset = ds.map(operations=compose)
- class mindspore.dataset.transforms.c_transforms.Concatenate(axis=0, prepend=None, append=None)[source]
Tensor operation that concatenates all columns into a single tensor.
- Parameters
axis (int, optional) – axis to concatenate the tensors along (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).
- class mindspore.dataset.transforms.c_transforms.Duplicate[source]
Duplicate the input tensor to a new output tensor. The input tensor is carried over to the output list.
Examples
>>> # Data before >>> # | x | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------+ >>> data = data.map(input_columns=["x"], operations=Duplicate(), >>> output_columns=["x", "y"], columns_order=["x", "y"]) >>> # Data after >>> # | x | y | >>> # +---------+---------+ >>> # | [1,2,3] | [1,2,3] | >>> # +---------+---------+
- class mindspore.dataset.transforms.c_transforms.Fill(fill_value)[source]
Tensor operation to create a tensor filled with passed scalar value. The output tensor will have the same shape and type as the input tensor.
- class mindspore.dataset.transforms.c_transforms.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 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
Examples
>>> # Data before >>> # | col1 | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------+ >>> data = data.map(operations=Mask(Relational.EQ, 2)) >>> # Data after >>> # | col1 | >>> # +--------------------+ >>> # | [False,True,False] | >>> # +--------------------+
- class mindspore.dataset.transforms.c_transforms.OneHot(num_classes)[source]
Tensor operation to apply one hot encoding.
- Parameters
num_classes (int) – Number of classes of the label.
- class mindspore.dataset.transforms.c_transforms.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 on integers representing the shape needed. Dimensions that set to None will not be padded (i.e., original dim will be used). Shorter dimensions will truncate the values.
pad_value (Union[str, bytes, int, float, bool]), optional) – value used to pad. Default to 0 or empty string in case of Tensors of strings.
Examples
>>> # Data before >>> # | col | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------| >>> data = data.map(operations=PadEnd(pad_shape=[4], pad_value=10)) >>> # Data after >>> # | col | >>> # +------------+ >>> # | [1,2,3,10] | >>> # +------------|
- class mindspore.dataset.transforms.c_transforms.RandomApply(transforms, prob=0.5)[source]
Randomly performs a series of transforms with a given probability.
- Parameters
Examples
>>> rand_apply = RandomApply([vision.RandomCrop()]) >>> dataset = ds.map(operations=rand_apply)
- class mindspore.dataset.transforms.c_transforms.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
>>> rand_choice = RandomChoice([vision.CenterCrop(), vision.RandomCrop()]) >>> dataset = ds.map(operations=rand_choice)
- class mindspore.dataset.transforms.c_transforms.Slice(*slices)[source]
Slice operation to extract a tensor out using the given n slices.
The functionality of Slice is similar to NumPy 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. Negative index is supported. 2.list[int]
: Slice these indices ion the list only. Negative indices are supported. 3.slice
: Slice the generated indices from the slice object. Similar to start:stop:step. 4.None
: Slice the whole dimension. Similar to : in python indexing. 5.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] | >>> # +---------|
- class mindspore.dataset.transforms.c_transforms.TypeCast(data_type)[source]
Tensor operation to cast to a given MindSpore data type.
- Parameters
data_type (mindspore.dtype) – mindspore.dtype to be casted to.
mindspore.dataset.transforms.py_transforms
This module py_transforms is implemented basing on python. It provides common operations including OneHotOp.