Skip to content

fix a bug in getting the value of prev_word_inds #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down