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

>>> import mindspore.dataset.vision.py_transforms as py_vision
>>> from mindspore.dataset.transforms.py_transforms import Compose
>>>
>>> Compose([py_vision.Decode(), py_vision.RandomHorizontalFlip(0.5),
>>>          py_vision.ToTensor()])