question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IndexError: list index out of range

See original GitHub issue

I have trained a model without self-critical, and run eval.py, an error occurs:

File "/host/xx/self-critical/eval_utils.py", line 143, in eval_split
    lang_stats = language_eval(dataset, predictions, eval_kwargs['id'], split)
  File "/host/xx/self-critical/eval_utils.py", line 39, in language_eval
    cocoRes = coco.loadRes(cache_path)
  File "/usr/local/lib/python3.5/dist-packages/pycocotools/coco.py", line 318, in loadRes
    if 'caption' in anns[0]:
IndexError: list index out of range

How should I do?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ivy94419commented, Aug 12, 2018

I have fixed this problem by change

entry = {'image_id': data['infos'][k]['id'], 'caption': sent}

to

entry = {'image_id': int(data['infos'][k]['file_path'].split('_')[-1].split('.')[0]), 'caption': sent} in eval_utils.py

0reactions
chenggui53commented, Feb 27, 2019

I have fixed this problem by change

entry = {'image_id': data['infos'][k]['id'], 'caption': sent}

to

entry = {'image_id': int(data['infos'][k]['file_path'].split('_')[-1].split('.')[0]), 'caption': sent} in eval_utils.py

@ivy94419 Thank you very much ! this help me solve the same problem in repo ruotianluo/ImageCaptioning.pytorch

Read more comments on GitHub >

github_iconTop Results From Across the Web

List Index Out of Range – Python Error Message Solved
You'll get the Indexerror: list index out of range error when iterating through a list and trying to access an item that doesn't...
Read more >
Python IndexError: List Index Out of Range Error Explained
Learn how to resolve the Python IndexError, list index out of range, why it occurs in for loops, while loops, and how to...
Read more >
Indexerror: list Index Out of Range in Python - STechies
In python “list index out of range” error occurs when we try to access an undefined element from the list. List index out...
Read more >
Python IndexError: List Index Out of Range [Easy Fix] - Finxter
The error “list index out of range” arises if you access invalid indices in your ...
Read more >
Index Error: list index out of range (Python) - Stack Overflow
Generally it means that you are providing an index for which a list element does not exist. E.g, if your list was [1,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found