mindspore.dataset.vision.py_transforms.ToTensor

class mindspore.dataset.vision.py_transforms.ToTensor(output_type=<class numpy.float32>)[source]

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 values in the input arrays are rescaled from [0, 255] to [0.0, 1.0]. The type is cast to output_type (default NumPy float32). The number of channels remains the same.

Parameters

output_type (NumPy datatype, optional) – The datatype of the NumPy output (default=np.float32).

Examples

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>> # create a list of transformations to be applied to the "image" column of each data row
>>> transforms_list = Compose([py_vision.Decode(),
...                           py_vision.RandomHorizontalFlip(0.5),
...                           py_vision.ToTensor()])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")