deep-learning-with-pytorch / dlwpt-code

Code for the book Deep Learning with PyTorch by Eli Stevens, Luca Antiga, and Thomas Viehmann.

Home Page:https://www.manning.com/books/deep-learning-with-pytorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

DemonsHunter opened this issue · 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~

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

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