question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Zero-dimensional tensor concatenation problem

See original GitHub issue

Hi 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:open
  • Created 5 years ago
  • Reactions:11
  • Comments:12

github_iconTop GitHub Comments

17reactions
frhfcommented, May 10, 2018

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 with torch.stack, but I am not entirely sure if this solution is unproblematic.

Regards Frank

11reactions
wujunyi627commented, Mar 10, 2019

I can run the code in pytorch in 0.4.1 version. you need to change the triplet.py(reid/loss triplet.py) image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to concatenate to a Tensor with a 0 dimension?
In Numpy I can do: np.hstack((np.zeros((3, 0)), np.zeros((3, 3))) and it would give me a 3x3 zero matrix.
Read more >
ValueError: zero-dimensional arrays cannot be concatenated
concatenate turns each of the items in the list into an array (if it isn't already), and tries to join them: In [129]:...
Read more >
zero-dimensional tensor (at position 0) cannot be ...
成功解决 RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated. 报错内容. 程序在这一步报错
Read more >
PyTorch - How to concatenate tensors along a given ...
In this program example, we concatenate two 2-dimensional tensors of different sizes along dimension 0 and 1. But you notice we can't ...
Read more >
tf.concat: Concatenate TensorFlow Tensors Along A Given ...
We are going to concatenate across the 0th dimension. Remember, Python is a zero-based index. And we're going to assign this concatenation to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found