Function differences with torchvision.transforms.ToPILImage

torchvision.transforms.ToPILImage

class torchvision.transforms.ToPILImage(
    mode=None
    )

For more information, see torchvision.transforms.ToPILImage.

mindspore.dataset.vision.ToPIL

class mindspore.dataset.vision.ToPIL

For more information, see mindspore.dataset.vision.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 as vision

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

image = np.random.random((64,64))
img = 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