Attemping to deploy my model to HuggingFace using Streamlit and
LoadLearner from fastAI. It is throwing an error that it’s missing the custom classes or functions.
I am having the same issue as the above.
Attribute error. Using Kaggle Notebooks to develop and export the
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’m not really sure what the cause of this problem is because you didn’t share a lot of code. If you could link your notebook with the error output in here (e.g. upload it to Kaggle, run it, share a link) I could try to help you more.
For now, I think it’s important to re-declare any functions that your exported model was using in the previous notebook. It sounds like your
GetLabel function and your model were in notebook A, where the model was then exported and importet in notebook B. In order for the model to work in notebook B, you need to re-declare
GetLabel in there too, or the model won’t work as it can’t use this function. Jeremy talks about it specifically here: Lesson 2: Practical Deep Learning for Coders 2022 - YouTube
Hope this helps.
Thanks a tonne. It does help alot. I have tried running the GetLabel function as part of creating the learner.
I’m confused as to where I would put the function in my deployment code. This is the first few lines including load_learner:
from fastai.vision.all import *
from fastai.learner import load_learner
#Load the Learner (Exported from ipnyb file with learn.export() )
learn = load_learner('export.pkl')
img = Image.create(cl_img)
pred, _ , _ = learn.predict(img)
Deploying using streamlit on HuggingFace
Thank you! It actually solved my problem and my classifier works. First deployed model. Simple but baby steps!