dlwpt-code icon indicating copy to clipboard operation
dlwpt-code copied to clipboard

Errata: p1ch7/2_bird_airplanes.ipynb, there is something wrong in "In[12]" part

Open DemonsHunter opened this issue 5 years ago • 2 comments

When I wrote codes according to p1ch7/2_bird_airplanes.ipynb, at the In[12] part, there was something wrong:

the original codes are: img, _ = cifar2[3] plt.imshow(img.permute(1, 2, 0) plt.show()

and the compiler told me:


AttributeError Traceback (most recent call last) in 1 img, _ = cifar2[3] ----> 2 plt.imshow(img.permute(1, 2, 0)) 3 plt.show()

AttributeError: 'Image' object has no attribute 'permute'


it turns out that the "img" here is an Image object rather than a tensor, so I rewrite it as following: img, _ = cifar2[3] plt.imshow(img) plt.show()

and this really works! Hope to help someone else~

DemonsHunter avatar Feb 09 '21 01:02 DemonsHunter

you need to load the images with transforms.ToTensor()

mamunm avatar Jun 17 '21 00:06 mamunm

img, _ = cifar2[0] img_t = to_tensor(img) plt.imshow(img_t.permute(1, 2, 0)) plt.show()

Just as mamunm say, this code works

lizhangtan avatar Dec 25 '22 08:12 lizhangtan