luo3300612 / image-captioning-DLCT

Official pytorch implementation of paper "Dual-Level Collaborative Transformer for Image Captioning" (AAAI 2021).
BSD 3-Clause "New" or "Revised" License
193 stars 31 forks source link

Expected all tensors to be on the same device #29

Open maryawwm opened 2 years ago

maryawwm commented 2 years ago

hello, I'm working on your code but on training step I got this error, I try to add .cuda() but it didn't work: Epoch 0 - validation: 100%|##########| 6250/6250 [11:39<00:00, 8.92it/s, loss=3.03] Epoch 0 - validation: 100%|##########| 6250/6250 [11:39<00:00, 8.93it/s, loss=3.03]

Epoch 0 - evaluation: 0%| | 0/250 [00:00<?, ?it/s] Epoch 0 - evaluation: 0%| | 0/250 [00:00<?, ?it/s] Traceback (most recent call last): File "train.py", line 354, in scores = evaluate_metrics(model, dict_dataloader_val, text_field) File "train.py", line 62, in evaluate_metrics {'boxes': boxes, 'grids': grids, 'masks': masks}) File "D:\thez\duallevel\DLCT\models\captioning_model.py", line 70, in beam_search return bs.apply(visual, out_size, return_probs, kwargs) File "D:\thez\duallevel\DLCT\models\beam_search\beam_search.py", line 71, in apply visual, outputs = self.iter(t, visual, outputs, return_probs, kwargs) File "D:\thez\duallevel\DLCT\models\beam_search\beam_search.py", line 104, in iter word_logprob = self.model.step(t, self.selected_words, visual.type(torch.LongTensor), None, mode='feedback', kwargs) File "D:\thez\duallevel\DLCT\models\DLCT\transformer.py", line 73, in step self.enc_output, self.mask_enc = self.encoder(regions=visual, grids=grids,boxes=boxes,aligns=aligns, region_embed=self.region_embed,grid_embed=self.grid_embed) File "C:\Users\MehrsysteM\anaconda3\envs\DLCT\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl return forward_call(*input, *kwargs) File "D:\thez\duallevel\DLCT\models\DLCT\encoders.py", line 189, in forward out_region = F.relu(self.fc_region(regions)) File "C:\Users\MehrsysteM\anaconda3\envs\DLCT\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl return forward_call(input, **kwargs) File "C:\Users\MehrsysteM\anaconda3\envs\DLCT\lib\site-packages\torch\nn\modules\linear.py", line 103, in forward return F.linear(input, self.weight, self.bias) File "C:\Users\MehrsysteM\anaconda3\envs\DLCT\lib\site-packages\torch\nn\functional.py", line 1848, in linear return torch._C._nn.linear(input, weight, bias) RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument mat2 in method wrapper_mm)

can you help me how to fix this?