Skip to content
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

File "main.py", line 222, in train losses.update(loss_triplet.data[0], num_items) IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number #28

Closed
monajalal opened this issue Sep 1, 2021 · 1 comment

Comments

@monajalal
Copy link

(fashcomp) [jalal@goku fashion-compatibility]$ python main.py --name test_baseline --learned --l2_embed --datadir ../../../data/fashion/
/scratch3/venv/fashcomp/lib/python3.8/site-packages/torchvision/transforms/transforms.py:310: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.
  warnings.warn("The use of the transforms.Scale transform is deprecated, " +
  + Number of params: 3191808
<class 'torch.utils.data.dataloader.DataLoader'>
/scratch3/venv/fashcomp/lib/python3.8/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
Traceback (most recent call last):
  File "main.py", line 324, in <module>
    main()    
  File "main.py", line 167, in main
    train(train_loader, tnet, criterion, optimizer, epoch)
  File "main.py", line 222, in train
    losses.update(loss_triplet.data[0], num_items)
IndexError: invalid index of a 0-dim tensor. Use `tensor.item()` in Python or `tensor.item<T>()` in C++ to convert a 0-dim tensor to a number

@monajalal
Copy link
Author

[Not sure if 100% makes sense or correct]
This change (## refers to old code)

    # measure accuracy and record loss
    ##losses.update(loss_triplet.data[0], num_items)
    ##accs.update(acc.data[0], num_items)
    ##emb_norms.update(loss_embed.data[0])
    ##mask_norms.update(loss_mask.data[0])
    
    losses.update(loss_triplet.data, num_items)
    accs.update(acc.data, num_items)
    emb_norms.update(loss_embed.data)
    mask_norms.update(loss_mask.data)

based on this suggestion NVIDIA/flownet2-pytorch#113 (comment) makes any sense if the error i was getting is non-existent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant