deep-learning-with-pytorch / dlwpt-code

Code for the book Deep Learning with PyTorch by Eli Stevens, Luca Antiga, and Thomas Viehmann.
https://www.manning.com/books/deep-learning-with-pytorch
4.67k stars 1.98k forks source link

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

Open DemonsHunter opened 3 years ago

DemonsHunter commented 3 years ago

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~
mamunm commented 3 years ago

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

lizhangtan commented 1 year ago

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