Skip to content
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

Single predictions list index out of range in foundation.py #521

Open
NZ369 opened this issue Mar 18, 2023 · 1 comment
Open

Single predictions list index out of range in foundation.py #521

NZ369 opened this issue Mar 18, 2023 · 1 comment

Comments

@NZ369
Copy link

NZ369 commented Mar 18, 2023

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)
in
----> 1 learn.predict(img)

20 frames
/usr/local/lib/python3.9/dist-packages/fastcore/foundation.py 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

Capture

@thewunder
Copy link

Same exact error trained via:

dls = ImageDataLoaders.from_folder(path, train='training', valid='testing')
learn = vision_learner(dls, resnet18, pretrained=False,
                loss_func=F.cross_entropy, metrics=accuracy)
learn.fit_one_cycle(1, 0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants