Bugs and improvements Chapter 2
BCJuan opened this issue · comments
Hi,
First of all: nice work. I am following your book to learn Pytorch.
The point is that, as also seen in #3 , there are some errors in the code. If you find it appropriate, I can make the changes and make a pull request.
The bugs are:
-
In function
loss_fn
:IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
simply changeloss.data[0]
byloss.item()
-
In function
plot_variable
you check if variable is typeVariable
but indeed they are type tensor. So solution would be to check is they aretorch.Tensor
. -
As I cloned the repo the panda image is in ìmages
so the line
panda = np.array(Image.open('../data/images/panda.jpg').resize((224,224)))gives.
FileNotFoundError: [Errno 2] No such file or directory: '../data/images/panda.jpg'Basically change the path to
'../images/B09301_03_12.jpg'`
Also this is not a bug but the dataset and dataloaders class could be exemplified by sampling a batch and visualizing.
That's all.
Thank you for everything.
Please reopen if the issue still persists.