mindspore.dataset.vision.Decode

View Source On Gitee
class mindspore.dataset.vision.Decode(to_pil=False)[source]

Decode the input image in RGB mode. Supported image formats: JPEG, BMP, PNG, TIFF, GIF(need to_pil=True ), WEBP(need to_pil=True ).

Parameters

to_pil (bool, optional) – Whether to decode the image to the PIL data type. If True, the image will be decoded to the PIL data type, otherwise it will be decoded to the NumPy data type. Default: False.

Raises
Supported Platforms:

CPU Ascend

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> # Eager usage
>>> import numpy as np
>>> raw_image = np.fromfile("/path/to/image/file", np.uint8)
>>> decoded_image = vision.Decode()(raw_image)
>>>
>>> # Pipeline usage
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> transforms_list = [vision.Decode(), vision.RandomHorizontalFlip()]
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns=["image"])
Tutorial Examples:
device(device_target='CPU')[source]

Set the device for the current operator execution.

Parameters

device_target (str, optional) – The operator will be executed on this device. Currently supports CPU . Default: CPU .

Raises
  • TypeError – If device_target is not of type str.

  • ValueError – If device_target is not CPU .

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.vision import Inter
>>>
>>> decode_op = vision.Decode().device("Ascend")
>>> resize_op = vision.Resize([100, 75], Inter.BICUBIC)
>>> transforms_list = [decode_op, resize_op]
>>> 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: