比较与torchvision.transforms.ToPILImage的功能差异
torchvision.transforms.ToPILImage
class torchvision.transforms.ToPILImage(
mode=None
)
mindspore.dataset.vision.ToPIL
class mindspore.dataset.vision.ToPIL
使用方式
PyTorch:将torch中的Tensor或numpy数组转换为PIL类型的图像。输入可以是<C, H, W> 格式的torch Tensor,或者<H, W, C> 格式的numpy数组。
MindSpore:输入为解码后的numpy数组,将其转换为PIL类型的图像。
代码示例
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