Cysu / open-reid

Open source person re-identification library in python
https://cysu.github.io/open-reid/
MIT License
1.33k stars 349 forks source link

IndexError: invalid index of a 0-dim tensor. #92

Closed absagargupta closed 4 years ago

absagargupta commented 4 years ago

Hello there. When I run the code: python examples/softmax_loss.py -d market1501 -b 64 -j 2 -a inception --logs-dir logs/softmax-loss/market1501-inception I get the following error. File "build/bdist.linux-x86_64/egg/reid/trainers.py", line 33, in train IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

The full traceback is as follows: Market1501 dataset loaded subset | # ids | # images

train | 651 | 11387 val | 100 | 1549 trainval | 751 | 12936 query | 750 | 16483 gallery | 751 | 19281 /usr/local/lib/python2.7/dist-packages/open_reid-0.2.0-py2.7.egg/reid/models/inception.py:130: UserWarning: nn.init.kaiming_normal is now deprecated in favor of nn.init.kaimingnormal. /usr/local/lib/python2.7/dist-packages/openreid-0.2.0-py2.7.egg/reid/models/inception.py:134: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant. /usr/local/lib/python2.7/dist-packages/openreid-0.2.0-py2.7.egg/reid/models/inception.py:135: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant. /usr/local/lib/python2.7/dist-packages/openreid-0.2.0-py2.7.egg/reid/models/inception.py:137: UserWarning: nn.init.normal is now deprecated in favor of nn.init.normal. /usr/local/lib/python2.7/dist-packages/openreid-0.2.0-py2.7.egg/reid/models/inception.py:139: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant. Traceback (most recent call last): File "examples/softmax_loss.py", line 217, in main(parser.parse_args()) File "examples/softmax_loss.py", line 147, in main trainer.train(epoch, train_loader, optimizer) File "build/bdist.linux-x86_64/egg/reid/trainers.py", line 33, in train IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number Any help will be appreciated

HenryZhangJianhe commented 4 years ago

do you solve this problem? I need your help!

qw85639229 commented 4 years ago

do you solve this problem? I need your help! Hi, you can change the loss.data[0] to loss.item().

HenryZhangJianhe commented 4 years ago

do you solve this problem? I need your help! Hi, you can change the loss.data[0] to loss.item().

thank you a lot!

But, when I use triplet_loss.py to run model with torch,version=1.5, I got error as follow: RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated How to fix it, thank you in advance!

qw85639229 commented 4 years ago

do you solve this problem? I need your help! Hi, you can change the loss.data[0] to loss.item().

thank you a lot!

But, when I use triplet_loss.py to run model with torch,version=1.5, I got error as follow: RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated How to fix it, thank you in advance!

You can just change the 'torch.cat()' to 'torch.stack()'. Hope this can help you solve the problem.

absagargupta commented 4 years ago

do you solve this problem? I need your help! Hi, you can change the loss.data[0] to loss.item().

This solved the problem.

HenryZhangJianhe commented 4 years ago

do you solve this problem? I need your help! Hi, you can change the loss.data[0] to loss.item().

thank you a lot! But, when I use triplet_loss.py to run model with torch,version=1.5, I got error as follow: RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated How to fix it, thank you in advance!

You can just change the 'torch.cat()' to 'torch.stack()'. Hope this can help you solve the problem.

yes, I have added '.unsqueeze(0)' to make it work refer to another issue image I think your idea is also good to work