Function differences with torchvision.transforms.ToPILImage

View Source On Gitee

torchvision.transforms.ToPILImage

class torchvision.transforms.ToPILImage(
    mode=None
    )

For more information, see torchvision.transforms.ToPILImage.

mindspore.dataset.vision.py_transforms.ToPIL

class mindspore.dataset.vision.py_transforms.ToPIL

For more information, see mindspore.dataset.vision.py_transforms.ToPIL.

Differences

PyTorch: Converts a tensor or numpy array to PIL Image. The input can be a torch Tensor in the format of <C, H, W>, or a numpy array in the format of <H, W, C>.

MindSpore: The input is a decoded numpy array, which is converted into a PIL type image.

Code Example

import numpy as np
import torch as T
from torchvision.transforms import ToPILImage
import mindspore.dataset.vision.py_transforms as py_vision

# In MindSpore, ToPIL transform the numpy.ndarray to PIL Image.

image = np.random.random((64,64))
img = py_vision.ToPIL()(image)
img.show()
# Out:
# window of PIL image

# In torch, ToPILImage transforms the input to PIL Image.
image = T.randn((64, 64))
img = ToPILImage()(image)
img.show()
# Out:
# window of PIL image