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
194 stars 31 forks source link

A code bug #14

Closed GX77 closed 2 years ago

GX77 commented 3 years ago

Traceback (most recent call last): File "/mnt/Pycharm_Remote/DLCT_test/train.py", line 335, in scores = evaluate_metrics(model, dict_dataloader_val, text_field) File "/mnt/Pycharm_Remote/DLCT_test/train.py", line 61, in evaluate_metrics {'boxes': boxes, 'grids': grids, 'masks': masks}) File "/mnt/Pycharm_Remote/DLCT_test/models/captioning_model.py", line 70, in beam_search return bs.apply(visual, out_size, return_probs, kwargs) File "/mnt/Pycharm_Remote/DLCT_test/models/beam_search/beam_search.py", line 71, in apply visual, outputs = self.iter(t, visual, outputs, return_probs, *kwargs) File "/mnt/Pycharm_Remote/DLCT_test/models/beam_search/beam_search.py", line 121, in iter self.model.apply_to_states(self._expand_state(selected_beam, cur_beam_size)) File "/mnt/Pycharm_Remote/DLCT_test/models/containers.py", line 30, in apply_to_states self._buffers[name] = fn(self._buffers[name]) File "/mnt/Pycharm_Remote/DLCT_test/models/beam_search/beam_search.py", line 27, in fn beam.expand(([self.b_s, self.beam_size] + shape[1:]))) RuntimeError: gather_out_cuda(): Expected dtype int64 for index

the beam is float and come from "selected_beam = selected_idx / candidate_logprob.shape[-1]",so it's float.But index need int.

GX77 commented 3 years ago

Hello, when I run the code directly, I get this error.

luo3300612 commented 3 years ago

This is casued by the different pytorch version. You can change this line to

selected_beam = (selected_idx / candidate_logprob.shape[-1]).long()