cyxanna / CAFE

This is the code for the paper "Cross-modal Ambiguity Learning for Multimodal Fake News Detection" of WWW2022.
66 stars 5 forks source link

IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) #4

Open Marium2020 opened 1 year ago

Marium2020 commented 1 year ago

I get the following error while running the train.py Can you suggest how to fix this? i tried x_out = torch.cat(x_out, dim=0), but that doesn't fix

Traceback (most recent call last): File "/content/drive/MyDrive/train.py", line 241, in train() File "/content/drive/MyDrive/train.py", line 98, in train text_aligned_match, image_aligned_match, pred_similarity_match = similarity_module(fixed_text, matched_image) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, kwargs) File "/content/drive/MyDrive/model.py", line 106, in forward text_encoding, image_encoding = self.encoding(text, image) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, *kwargs) File "/content/drive/MyDrive/model.py", line 70, in forward text_encoding = self.shared_text_encoding(text) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(input, kwargs) File "/content/drive/MyDrive/model.py", line 33, in forward x_out = torch.cat(x_out, 1) IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

cyxanna commented 1 year ago

Hi,

Thanks for using CAFE. As we can see that the error message states that "IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)", which means the tensor x_out is expected to be a matrix, not a vector. Maybe there is something wrong with your data pre-processing or data-flow? A careful check on the dimension alignment between the data and the model might be quite helpful.

: )

zhangmingdao commented 1 year ago

hello,did you solve the problem?

decode12 commented 1 year ago

hello,firstly,thanks yours source.I meet the same question

zhangmingdao commented 1 year ago

hello,firstly,thanks yours source.I meet the same question

I solve it.you can make the epoch/batchsize an interger number.

decode12 commented 1 year ago

first,thank you,I also solve it,but anther approach.may be the tensor problem,i will try your approach.

ac6841d20e94155f1b00029a39a64d5 3b526b4fba3709d73bda4cf6201f569
weiSENshu commented 1 year ago

把batch_size设置成除了64的其他数值,就可以正常运行。我分别试了60,65,128,256,512都能正常运行,只有设成64,会出现上述错误