Cannot import load_learner

My system automatically updated from fastai v1 to v2. I have a text model that has been in production and 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 to predict.

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

I would like to restore my previous function as that had no issues so 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!

I don’t think there is a fastai v1.4.0. Do you mean PyTorch 1.4.0?

I don’t think fastai v1 models will work with fastai v2 library, unfortunately.

Hello @helenas
I have the same issue : ImportError: cannot import name 'load_learner' from ''
I have python 3.8.2 and I’m unable to install fastai v1
pip install fastai automatically installs fastai==2.0.6

Is there any solution to be able to import / use load_learner in fastai 2 ? Or to install fastai 1 with python 3.8 ? :face_with_monocle:

Thank you :pray:

hello @alaeddinez
I have used pip install from fastai gitlab archives for fastai v1, but load_learner() doesn’t work in this version (1.0.34) for me.

pip install

appreciate any thoughts or input from others on how to install the last updated version of fastai v1 before it was updated to v2

Hello @helenas,
I didn’t find a proper way to install previous fastai version while using python 3.8
When doing pip install fastai==1.0.57 or whatever 1.0.x version, I encounter a problem with pynvx

The only way I found is :

  • installing fastai without dependencies : pip install --no-deps fastai
  • manually installing the dependencies using pip command (except pynvx and bottleneck which caused a problem for me)

that allows me to have fastai v1 with python 3.8 on macOS. I tried
from import load_learner and that works

Tell me if that helps !

is there any way to do the same for fastai v2

the community for fast ai looks very small, people normally are not able to find answer and had to look toward other algos unfortunately. I am algo going back to conventional networks, After spending hours no solution.

I used fastai v2
and the import: from import *
this works

Thanks for all the tips guys, I was missing this import since I thought from fastai import * would import everything including the vision submodule.

Could anyone explain why you still need to import submodules separately? I thought the whole purpose of importing all from fastai is so you don’t need to do this anymore.

Did this get solved?

I too want from import load_learner instead of from import *

To address this thread, if you are using fastai v2 you can import load_learner one of two ways:

  1. from fastai.{module_name}.all import *, in v2 just doing from fastai.module import * will not do it
  2. from fastai.learner import load_learner

Both didn’t work for me ;( :

  1. from import *
  2. from fastai.learner import load_learner

Please check StackOverflow post

For you specifically the error is extremely straightforward. You declared code when you were originally training that isn’t from the fastai library. This code needs to be available in python before calling load_learner.

A prime example of this is say you used a custom label function, like:

def my_label_func(a): return

If I try importing my Learner without having my_label_func declared somewhere, you will face the same error.

1 Like

Yes; I’ll need the original code that made the model .pkl file. I’ll keep you updated. Thanks man

What happens when the function is not one I custom created but is one found within the first lesson of

I’m getting the following error:

AttributeError: Custom classes or functions exported with your `Learner` are not available in the namespace currently.
Please re-declare or import them before calling `load_learner`:
	Can't get attribute 'Resampling' on 

After simply trying to load my pickled model.

I don’t know what the Resampling function is, to know how to load it. I assumed it was built within fastai but doesn’t seem to be the case.

fastai.version == 2.7.7

I am having the same issue as the above. Attribute error. Using Kaggle Notebooks to develop and export the .pkl file

I’m running the load_learner and it is giving me the attribute error missing a custom function which in my case is my GetLabel from the food classifier exercise

Does anyone know where in the code to declare that original function? It actually happened in the Production example of Chapter two from the 2022 course as well.

Thanks. Excited for deployment!


I think you run GetLabel before you run the load_learner as the error suggests.
With Resampling error, I’m not sure what’s going on. Maybe try finding Resampling definition from source code and try to run it?