L1aoXingyu / pytorch-beginner

pytorch tutorial for beginners
3k stars 1.09k forks source link

04-Convolutional-Neural-Network两个问题 #37

Open LittleStar-Angel opened 4 years ago

LittleStar-Angel commented 4 years ago

1from logger import Logger有警告 2D:\Anaconda3\python.exe G:/pytorch/pytorch-beginner-master/04-Convolutional-Neural-Network/convolution_network.py epoch 1


Traceback (most recent call last): File "G:/pytorch/pytorch-beginner-master/04-Convolutional-Neural-Network/convolution_network.py", line 78, in running_loss += loss.data[0] * label.size(0) IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

Process finished with exit code 1

微信图片_20200524170216

image

baizhenfeng commented 4 years ago

出现:“IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number”,这是PyTorchd 版本问题。 将.data[0]全部改为.item()。 希望可以解决您的问题,祝好!

LittleStar-Angel commented 4 years ago

好的,谢谢