tensorflow / tensorflow/models

Line 182 in `caption_generator.py` of `im2txt` should be `[-self.beam_size:]` instead of `[:-self.beam_size]` since the comment above explicitly says the "last `beam_size` elements"

Open
#6,513 5 comments 3 reactions 1 assignee View on GitHub

@cshallue is already working on this.

Since Jul 1, 2020.

models:research type:support
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

System information
  • What is the top-level directory of the model you are using: research/im2txt
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04
  • TensorFlow installed from (source or binary): binary, anaconda
  • TensorFlow version (use command below): b'unknown' 1.12.0
  • Bazel version (if compiling from source): 0.22.0- (@non-git)
  • CUDA/cuDNN version: 10.1
  • GPU model and memory: GeForce GTX 1080 / 8116MiB
  • Exact command to reproduce: N/A
Describe the problem

Line 182 in caption_generator.py of im2txt should be [-self.beam_size:] instead of [:-self.beam_size], since the comment above explicitly says the "last beam_size elements".

    # For this partial caption, get the beam_size most probable next words.
    # Sort the indexes with numpy, select the last self.beam_size
    # (3 by default) (ie, the most likely) and then reverse the sorted
    # indexes with [::-1] to sort them from higher to lower.
    most_likely_words = np.argsort(word_probabilities)[:-self.beam_size][::-1]

run_inference will output length 1 description without this, like

Captions for image COCO_val2014_000000224477.jpg:
  0)  (p=0.000000)
  1) surfer (p=0.000000)
  2) man (p=0.000000)

while it will output much more "normal" output with this:

Captions for image COCO_val2014_000000224477.jpg:
  0) a person riding a surf board on a wave <S> <S> <S> <S> <S> <S> <S> <S> . (p=0.000896)
  1) a person riding a surf board on a wave <S> <S> <S> <S> <S> <S> . <S> <S> (p=0.000732)
  2) a person riding a surf board on a wave <S> <S> <S> <S> <S> . <S> <S> <S> (p=0.000456)
Source code / logs

N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.