aaron-xichen / pytorch-playground

Base pretrained models and datasets in pytorch (MNIST, SVHN, CIFAR10, CIFAR100, STL10, AlexNet, VGG16, VGG19, ResNet, Inception, SqueezeNet)
MIT License
2.62k stars 612 forks source link

Fix complaints about 0-dim tensor #43

Closed gussmith23 closed 4 years ago

gussmith23 commented 4 years ago
Traceback (most recent call last):
  File "mnist/train.py", line 88, in <module>
    loss.data[0], acc, optimizer.param_groups[0]['lr']))
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

and

Traceback (most recent call last):
  File "mnist/train.py", line 108, in <module>
    test_loss += F.cross_entropy(output, target).data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
aaron-xichen commented 4 years ago

good job~