mindspore.dataset.vision.py_transforms.ToTensor
- class mindspore.dataset.vision.py_transforms.ToTensor(output_type=np.float32)[source]
Convert the input PIL Image or numpy.ndarray to numpy.ndarray of the desired dtype. At the same time, the range of pixel value will be changed from [0, 255] to [0.0, 1.0] and the shape will be changed from (H, W, C) to (C, H, W).
- Parameters
output_type (numpy.dtype, optional) – The desired dtype of the output image. Default:
numpy.float32
.- Raises
TypeError – If the input image is not of type
PIL.Image.Image
ornumpy.ndarray
.TypeError – If dimension of the input image is not 2 or 3.
- Supported Platforms:
CPU
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")