Zero-dimensional tensor concatenation problem
See original GitHub issueHi there,
Thank you for the code!
While training the ResNet50 model using the market1501 dataset, I got the following Runtime error:
Traceback (most recent call last):
File "examples/triplet_loss.py", line 232, in <module>
main(parser.parse_args())
File "examples/triplet_loss.py", line 151, in main
trainer.train(epoch, train_loader, optimizer)
File "/home/bxpan/.local/lib/python3.5/site-packages/open_reid-0.2.0-py3.5.egg/reid/trainers.py", line 33, in train
File "/home/bxpan/.local/lib/python3.5/site-packages/open_reid-0.2.0-py3.5.egg/reid/trainers.py", line 83, in _forward
File "/home/bxpan/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in __call__
result = self.forward(*input, **kwargs)
File "/home/bxpan/.local/lib/python3.5/site-packages/open_reid-0.2.0-py3.5.egg/reid/loss/triplet.py", line 26, in forward
RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated
The problem turned out to happen at this specific line of code in triplet.py
:
dist_ap = torch.cat(dist_ap)
I have printed out dist_ap
, which is a python list full of zero-dimensional (its printed-out size is: torch.Size([])
) tensors (I used a batch-size of 64 so the list has a length of 64):
[tensor(0.2895, device='cuda:0'), tensor(0.3334, device='cuda:0'), tensor(0.3334, device='cuda:0'), tensor(0.3175, device='cuda:0'), tensor(0.3078, device='cuda:0'), tensor(0.3078, device='cuda:0'), tensor(0.3045, device='cuda:0'), tensor(0.3045, device='cuda:0'), tensor(0.2636, device='cuda:0'), tensor(0.2630, device='cuda:0'), tensor(0.2497, device='cuda:0'), tensor(0.2636, device='cuda:0'), tensor(0.2967, device='cuda:0'), tensor(0.2657, device='cuda:0'), tensor(0.2967, device='cuda:0'), tensor(0.2936, device='cuda:0'), tensor(0.3517, device='cuda:0'), tensor(0.2939, device='cuda:0'), tensor(0.3517, device='cuda:0'), tensor(0.3185, device='cuda:0'), tensor(0.3318, device='cuda:0'), tensor(0.3357, device='cuda:0'), tensor(0.3260, device='cuda:0'), tensor(0.3357, device='cuda:0'), tensor(0.2928, device='cuda:0'), tensor(0.2906, device='cuda:0'), tensor(0.2928, device='cuda:0'), tensor(0.2906, device='cuda:0'), tensor(0.1992, device='cuda:0'), tensor(0.2086, device='cuda:0'), tensor(0.2086, device='cuda:0'), tensor(0.2040, device='cuda:0'), tensor(0.2742, device='cuda:0'), tensor(0.2836, device='cuda:0'), tensor(0.3117, device='cuda:0'), tensor(0.3117, device='cuda:0'), tensor(0.2838, device='cuda:0'), tensor(0.2686, device='cuda:0'), tensor(0.2435, device='cuda:0'), tensor(0.2838, device='cuda:0'), tensor(0.3124, device='cuda:0'), tensor(0.3268, device='cuda:0'), tensor(0.3304, device='cuda:0'), tensor(0.3304, device='cuda:0'), tensor(0.2591, device='cuda:0'), tensor(0.2671, device='cuda:0'), tensor(0.2825, device='cuda:0'), tensor(0.2825, device='cuda:0'), tensor(0.3309, device='cuda:0'), tensor(0.2836, device='cuda:0'), tensor(0.3126, device='cuda:0'), tensor(0.3309, device='cuda:0'), tensor(0.3232, device='cuda:0'), tensor(0.3493, device='cuda:0'), tensor(0.3493, device='cuda:0'), tensor(0.3379, device='cuda:0'), tensor(0.3044, device='cuda:0'), tensor(0.3173, device='cuda:0'), tensor(0.3173, device='cuda:0'), tensor(0.3009, device='cuda:0'), tensor(0.2941, device='cuda:0'), tensor(0.3048, device='cuda:0'), tensor(0.3048, device='cuda:0'), tensor(0.2704, device='cuda:0')]
The values of the tensors seem to be of no problem, but the concatenation fails. Any idea about what the problem is?
Thank you very much.
Boxiao
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:12
Top GitHub Comments
Hi,
I got the same problem recently. I think it is connected to a newer version of pytorch.
What worked for me is replacing
torch.cat
withtorch.stack
, but I am not entirely sure if this solution is unproblematic.Regards Frank
I can run the code in pytorch in 0.4.1 version. you need to change the triplet.py(reid/loss triplet.py)