添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

def img_convert(tensor):
image = tensor.clone().detach().numpy()
image = image.transpose(1, 2, 0)
print(image.shape)
image = image*np.array(0.5,) + np.array(0.5,)
image = image.clip(0, 1)
return image

dataiter = iter(training_loader)
images, labels = dataiter.next()
fig = plt.figure(figsize=(25, 4))

for idx in np.arange(20):
ax = fig.add_subplot(2, 10, idx+1, xticks=[], yticks=[])
plt.imshow(img_convert(images[idx]))
ax.set_title([labels[idx].item()])

Can someone help me with this error can’t figure out how to resolve this, first I had gray scale problem then after fixing it there is a new issue.
Invalid dimension for image data

On printing the shape of images[idx] I find the shape is reversed
Output:
torch.Size([1, 28, 28])
(28, 28, 1)

However if I put a transpose command
images[idx].transpose(1, 2, 0)
so which 2 positional arguments should I give

If you are dealing with grayscale images, you should remove the channel dimension for matplotlib :

plt.imshow(np.random.randn(24, 24, 3)) # works
plt.imshow(np.random.randn(24, 24)) # works
plt.imshow(np.random.randn(24, 24, 1)) # fails
              

@ptrblck I was having a Tiff file dataset and the problem am having is ,couldn’t plot the tiff file and these are the following information about the tiff file.
Screenshot 2023-05-10 at 1.10.31 AM2056×846 102 KB and this is the following error, could know where is the problem.
Screenshot 2023-05-10 at 1.12.00 AM2596×1174 256 KB and these are the following functions to convert from tiff to image array and display the tiff file
Screenshot 2023-05-10 at 1.14.03 AM2368×816 116 KB

here is the following link to colab Notebook
plss tell me , how to resolve this problem