Getting an error while running a flask application that is using a already saved model that uses Timm

Before I trained a model with Timm my application worked perfectly when reading an older model. However when I implemented a new model using convnext and the library Timm I got this 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 'TimmBody' on <module 'fastai.vision.learner' from '/home/app/lib/python3.9/site-packages/fastai/vision/learner.py'>

I already put Timm in my requirements.txt file at the start and run pip -r requirements.txt --no-cache with a new python environment that uses the 3.9 version. I also import Timm in the root of the application and later I read from the model .pkl

After two days, it seems no-one knows off the top of their head.

So a general tip: Error messages are very searchable. You’ll have a better chance of a solution if you summarise for readers what you have learned from searching your error message, like this…
Google: 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

This might help you provide more targeted questions that are easier to answer, as explained in HTAQTSW.

1 Like

Sorry I already solved the issue. I needed to upgrade my fastai version to the new one.