mindspore.dataset.vision.ToNumpy

class mindspore.dataset.vision.ToNumpy[source]

Convert the PIL input image to numpy.ndarray image.

Supported Platforms:

CPU

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.transforms import Compose
>>>
>>> # Use the transform in dataset pipeline mode
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
>>> # Use ToNumpy to explicitly select C++ implementation of subsequent op
>>> transforms_list = Compose([vision.RandomHorizontalFlip(0.5),
...                            vision.ToNumpy(),
...                            vision.Resize((50, 60))])
>>> # apply the transform to dataset through map function
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["image"].shape, item["image"].dtype)
...     break
(50, 60, 3) uint8
>>>
>>> # Use the transform in eager mode
>>> data = list(np.random.randint(0, 255, size=(32, 32, 3, 3)).astype(np.int32))
>>> output = vision.ToNumpy()(data)
>>> print(type(output), output.shape, output.dtype)
<class 'numpy.ndarray'> (32, 32, 3, 3) int32
Tutorial Examples: