mindspore.dataset.vision.ToTensor

View Source On Gitee
class mindspore.dataset.vision.ToTensor(output_type=np.float32)[source]

Convert the input PIL Image or numpy.ndarray to numpy.ndarray of the desired dtype, rescale the pixel value range from [0, 255] to [0.0, 1.0] and change the shape from <H, W, C> to <C, H, W>.

Parameters

output_type (Union[mindspore.dtype, numpy.dtype], optional) – The desired dtype of the output image. Default: np.float32 .

Raises
Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.transforms import Compose
>>>
>>> # create a list of transformations to be applied to the "image" column of each data row
>>> transforms_list = Compose([vision.Decode(to_pil=True),
...                            vision.RandomHorizontalFlip(0.5),
...                            vision.ToTensor()])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")
Tutorial Examples: