From 0d0be3b26ef713fe310afbd3bb254b90b9751cd6 Mon Sep 17 00:00:00 2001 From: moon Date: Thu, 28 Jul 2022 16:22:56 +0800 Subject: [PATCH 1/3] fix a bug in getting the value of prev_word_inds "//" cannot be used directly, because if the value of tensor is negative, it is equivalent to "trunc", not "floor" --- eval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eval.py b/eval.py index 3e9359a09..52801f2b0 100644 --- a/eval.py +++ b/eval.py @@ -121,7 +121,7 @@ def evaluate(beam_size): top_k_scores, top_k_words = scores.view(-1).topk(k, 0, True, True) # (s) # Convert unrolled indices to actual indices of scores - prev_word_inds = top_k_words / vocab_size # (s) + prev_word_inds = torch.div(top_k_words, vocab_size, rounding_mode='floor') # (s) next_word_inds = top_k_words % vocab_size # (s) # Add new words to sequences From 43d0ea265e9c98ade05a63c1eaa734893fd1e89c Mon Sep 17 00:00:00 2001 From: moon Date: Thu, 28 Jul 2022 16:50:56 +0800 Subject: [PATCH 2/3] fix a same bug in getting the value of prev_word_inds --- caption.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caption.py b/caption.py index 8ca071905..eb51f5449 100644 --- a/caption.py +++ b/caption.py @@ -104,7 +104,7 @@ def caption_image_beam_search(encoder, decoder, image_path, word_map, beam_size= top_k_scores, top_k_words = scores.view(-1).topk(k, 0, True, True) # (s) # Convert unrolled indices to actual indices of scores - prev_word_inds = top_k_words / vocab_size # (s) + prev_word_inds = torch.div(top_k_words, vocab_size, rounding_mode='floor') # (s) next_word_inds = top_k_words % vocab_size # (s) # Add new words to sequences, alphas From a8032d20d1dff40c0e683324bbd6d9e020040343 Mon Sep 17 00:00:00 2001 From: moon Date: Thu, 28 Jul 2022 16:54:12 +0800 Subject: [PATCH 3/3] fix a parameter bug in "plt.subplot" Number of rows must be a positive integer --- caption.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caption.py b/caption.py index eb51f5449..eee8f328f 100644 --- a/caption.py +++ b/caption.py @@ -167,7 +167,7 @@ def visualize_att(image_path, seq, alphas, rev_word_map, smooth=True): for t in range(len(words)): if t > 50: break - plt.subplot(np.ceil(len(words) / 5.), 5, t + 1) + plt.subplot(int(np.ceil(len(words) / 5.)), 5, t + 1) plt.text(0, 1, '%s' % (words[t]), color='black', backgroundcolor='white', fontsize=12) plt.imshow(image)