mindspore.dataset.vision.Decode
- 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
RuntimeError – If given tensor is not a 1D sequence.
RuntimeError – If the input is not raw image bytes.
RuntimeError – If the input image is already decoded.
- Supported Platforms:
CPU
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: