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
learn.predict(text)
I would like to restore my previous function as that had no issues so I have installed fastai v1 with pip install https://github.com/fastai/fastai1/archive/master.zip 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!
Hello @helenas
I have the same issue : ImportError: cannot import name 'load_learner' from 'fastai.vision'
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 ?
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 fastai.vision import load_learner and that works
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.
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.
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 a.name
If I try importing my Learner without having my_label_func declared somewhere, you will face the same error.
What happens when the function is not one I custom created but is one found within the first lesson of fast.ai?
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.
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.
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?