PyCharm设置调式时可预览PyTorch Tensor图像

from PIL import Image
from torchvision.transforms import ToTensor
img = Image.open("D:\\Downloads\\IMG_20240226_121645.jpg")
toTensor = ToTensor()
img = toTensor(img)

Shape of PIL: [Height, Width, Channels]
Shape of PyTorch: [Batch, Channels, Height, Width]

Settings - Live Templates:
Add to Python:
Abbreviation:debug_show
Template text:
import matplotlib.pyplot as plt
import numpy
pic = $VAR_NAME$
#cpu
#pic = numpy.transpose(pic, axes=[1, 2, 0])
#cuda
pic = numpy.transpose(pic.cpu(), axes=[1, 2, 0])
plt.imshow(pic, cmap='gray')
plt.show()

Change:Python

Useage:
Debug Mode - Mouse Right Button - Evaluate Expression
Input debug_show and varname

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

9 − 3 =