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.

RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 3 and 2

See original GitHub issue

Hi,Thank you for this perfect code,and I have learned a lot from this code.But when I run this code,I get one problem : Traceback (most recent call last): File "main.py", line 438, in <module> train(data, save_model_dir, seg) File "main.py", line 265, in train batch_charrecover, batch_label, mask) File "/Users/fengxiachong/Desktop/PyTorchSeqLabel-master/model/bilstmcrf.py", line 33, in neg_log_likelihood_loss scores, tag_seq = self.crf._viterbi_decode(outs, mask) File "/Users/fengxiachong/Desktop/PyTorchSeqLabel-master/model/crf.py", line 162, in _viterbi_decode partition_history = torch.cat(partition_history).view(seq_len, batch_size, -1).transpose(1, RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 3 and 2 at /Users/soumith/minicondabuild3/conda-bld/pytorch_1518371252923/work/torch/lib/TH/generic/THTensorMath.c:2888 could you please help me?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
ghostcommented, Feb 26, 2018

I just add one line partition = partition.view(partition.size()[0], partition.size()[1], 1)in function _viterbi_decode in the for loop,now it can run,thank you very much.

4reactions
Shuailongcommented, Feb 26, 2018

partition = partition.unsqueeze(-1) works also.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytorch DataLoader: `Tensors must have same number of ...
I am using 365 timesteps of X1 & X2 as features used to predict y . The dimensions of my training array is:...
Read more >
Sizes of tensors must match except in dimension 0. Got 3 and ...
RuntimeError : invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 2 in dimension 1. It is...
Read more >
RuntimeError: invalid argument 0: Tensors must have same ...
Error1: mean = torch.cat([mean, y], 1) RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 2 and 4 at /pytorch/ ......
Read more >
Tabular data: Tensors must have same number of dimensions
RuntimeError : invalid argument 0: Tensors must have same number of dimensions: got 1 and 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:680.
Read more >
runtimeerror: sizes of tensors must match except in dimension ...
Pytorch RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0 2 PyTorch LSTM:...
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