mindspore.dataset.vision.ToType
- class mindspore.dataset.vision.ToType(data_type)[source]
Cast the input to a given MindSpore data type or NumPy data type.
It is the same as that of
mindspore.dataset.transforms.TypeCast
.Note
This operation supports running on Ascend or GPU platforms by Offload.
- Parameters
data_type (Union[mindspore.dtype, numpy.dtype]) – The desired data type of the output image, such as
numpy.float32
.- Raises
TypeError – If data_type is not of type
mindspore.dtype
ornumpy.dtype
.
- Supported Platforms:
CPU
Ascend
GPU
Examples
>>> import numpy as np >>> from mindspore.dataset.transforms import Compose >>> >>> transforms_list = Compose([vision.Decode(to_pil=True), ... vision.RandomHorizontalFlip(0.5), ... vision.ToTensor(), ... vision.ToType(np.float32)]) >>> # apply the transform to dataset through map function >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns="image")