AnswerDotAI / AnswerDotAI/fastcore
Single predictions list index out of range in foundation.py
- Dominant language
- Jupyter Notebook
- Stars
- 1.1k
- Forks
- 295
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 7
Description
After loading a model when conduction single predictions, there is a list index out of range issue. The issue is located in foundation.py file, specifically line 120 (else [self.items[i_] for i_ in i]) which assumes batch input.
Input code:
! [ -e /content ] && pip install -Uqq fastbook
import fastbook
fastbook.setup_book()
from fastai.vision.all import *
learn = load_learner('export.pkl')
learn.predict(img)
Error output:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
[](https://localhost:8080/#) in
----> 1 learn.predict(img)
20 frames
[/usr/local/lib/python3.9/dist-packages/fastcore/foundation.py](https://localhost:8080/#) in (.0)
118 return (self.items.iloc[list(i)] if hasattr(self.items,'iloc')
119 else self.items.__array__()[(i,)] if hasattr(self.items,'__array__')
--> 120 else [self.items[i_] for i_ in i])
121
122 def __setitem__(self, idx, o):
IndexError: list index out of range

Contributor guide
Research direction
Start at foundation.py line 120 and reproduce the failure with the provided fastai learner and learn.predict(img) example. Trace how single-item and batch indices reach this list access; done means single predictions no longer raise IndexError while batch indexing still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100