New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UserWarning: invalid index of a 0-dim tensor #6061
Comments
I think you need solve the problem of the type of correct, I believe that the type of correct you get is 'byteTensor'. |
I'm sorry to hear that, I've had this problem before, I hope my idea can help you. |
You might have to change |
Yes, this is a side effect of Variable/Tensor merge. Follow the error message (or cast it explicitly to a float with |
/home/kerax/usys/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:31: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number Iter: 0, D: 1.351, G:0.6499 |
see issue: pytorch/pytorch#6061 (comment)
I got the same error but fixed it with loss.item() as [vishwakftw] mentioned above. Thank you |
Thank for [vishwakftw], this is the pytorch'version problem |
I am getting this error, does anyone knows how to solve it, Thanks in advance! IndexError Traceback (most recent call last) in () in train_model(model, criterion, optimizer, train_loader, validation_loader, n_epochs, save_file_name) IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number |
I am getting this error, does anyone knows how to solve it, Thanks in advance! IndexError Traceback (most recent call last) in () in train_model(model, criterion, optimizer, train_loader, validation_loader, n_epochs, save_file_name) IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number |
Follow the instructions in the error message |
When I installed the newest version of pytorch with source code ,I got the error :
UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
train_loss += loss.data[0]
Traceback (most recent call last):......................... 10/2984 Step: 61ms | Tot: 2s170ms | Loss: File "testgn.py", line 267, in
train(epoch)
File "testgn.py", line 199, in train
% (train_loss/(batch_idx+1), 100.*correct/total, correct, total))
RuntimeError: value cannot be converted to type uint8_t without overflow: 264
By the way,the code runs well on the pytorch installed by conda.
The text was updated successfully, but these errors were encountered: