Getting load_learner not defined

Kindly find the response inline:
from fastai import *
from import *
from import image
model = load_learner("./weights/",‘mobilenetv2_8epochs_best.pkl’)

Was getting NameError: name ‘load_learner’ is not defined in fast ai version 2.0
for fast ai version 1.6 it is working fine

Kindly help


Since release fastai2 (few days ago) , name pip package “fastai” becomes fastai in version 2
and your code applies to version 1

You may install fastai version 1 directly from repo if you have to.

pip install

But it is preferable to switch to version 2 (but you will have to migrate your network)

It’s not that it’s not defined, importing in fastai2 is different. Please read the documentation for examples. Also fastai2 is not backwards compatible with v1, so you should do as @Kornel, otherwise you’ll fail.

Hi, I am facing a similar issue.
I have a fastai text model that was trained from fastai v1. It is stored in Microsoft Azure Storage as a block blob and I have been using load_learner to load it from a file path and run it on a model in production.

from fastai import load_learner
path = ‘/dbfs/mnt/lake/users/helena_shi’
learn = load_learner(path, ‘final_whole’)

I have installed fastai v1 with pip install but that only installs fastai v1.0.34 when I need 1.4.0 to use load_learner.
Alternatively, does fastai v2 have a similiar function to directly load a model from a path and predict with or do I need to retrain my existing model with the new syntax?
Please advise - thank you!


Did you ever get this figured out? I am using fastai v2.4. My model was trained on Google on 2-17-21 after the release of fastai2. I assume that means that my model was created using v2 but I am not positive.
Not sure if that makes a difference seeing as how the error is that load_learner is not defined which in my mind has nothing to do with creating the model as others have suggested.

I am facing same issue. but nobody has given any solution to this issue yet ?

I ended up reinstalling previous versions of fastai and torch to get around the upgrade, as I had models already trained with fastai v1.

!pip install torch==1.7.1
!pip install torchvision==0.1.8
!pip install fastai==1.0.60