ruotianluo / self-critical.pytorch

Unofficial pytorch implementation for Self-critical Sequence Training for Image Captioning. and others.
MIT License
991 stars 278 forks source link

Error training "RuntimeError: mat1 dim 1 must match mat2 dim 0" #262

Open nathanielhobbs opened 2 years ago

nathanielhobbs commented 2 years ago

When running the command pyhon tools/train.py --cfg configs/fc.yml --id fc

I get the following traceback: Traceback (most recent call last):

File "/scratch/nh385/self-critical.pytorch/tools/train.py", line 185, in train

model_out = dp_lw_model(fc_feats, att_feats, labels, masks, att_masks, data['gts'], torch.arange(0, len(data['gts'])), sc_flag, struc_flag, drop_worst_flag) 

File "/home/nh385/anaconda3/envs/xlinear/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl

result = self.forward(*input, **kwargs) 

File "/home/nh385/anaconda3/envs/xlinear/lib/python3.9/site-packages/torch/nn/parallel/data_parallel.py", line 159, in forward

return self.module(*inputs[0], **kwargs[0]) 

File "/home/nh385/anaconda3/envs/xlinear/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl

result = self.forward(*input, **kwargs) 

File "/scratch/nh385/self-critical.pytorch/captioning/modules/loss_wrapper.py", line 47, in forward

loss = self.crit(self.model(fc_feats, att_feats, labels[..., :-1], att_masks), labels[..., 1:], masks[..., 1:], reduction=reduction) 

File "/home/nh385/anaconda3/envs/xlinear/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl

result = self.forward(*input, **kwargs) 

File "/scratch/nh385/self-critical.pytorch/captioning/models/CaptionModel.py", line 33, in forward

return getattr(self, '_'+mode)(*args, **kwargs) 

File "/scratch/nh385/self-critical.pytorch/captioning/models/AttModel.py", line 136, in _forward

p_fc_feats, p_att_feats, pp_att_feats, p_att_masks = self._prepare_feature(fc_feats, att_feats, att_masks) 

File "/scratch/nh385/self-critical.pytorch/captioning/models/AttModel.py", line 943, in _prepare_feature

fc_feats = self.fc_embed(fc_feats) 

File "/home/nh385/anaconda3/envs/xlinear/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl

result = self.forward(*input, **kwargs) 

File "/home/nh385/anaconda3/envs/xlinear/lib/python3.9/site-packages/torch/nn/modules/linear.py", line 93, in forward

return F.linear(input, self.weight, self.bias) 

File "/home/nh385/anaconda3/envs/xlinear/lib/python3.9/site-packages/torch/nn/functional.py", line 1690, in linear

ret = torch.addmm(bias, input, weight.t()) 

RuntimeError: mat1 dim 1 must match mat2 dim 0