Cnn_learner returning a 'Sequential' object with missing methods

Hi ! First of all, my apologies for the stupidity of my question because it has been 3 years since I last used fastai and the library has changed a lot.
I have some problems using the learner, especially its different methods. I would like to call lr_find but I end up with this error.

from fastai.vision.data import ImageDataLoaders
from fastai.vision.augment import Resize
from fastai.vision.learner import cnn_learner
from fastai.metrics import accuracy, Precision, Recall, F1Score
from torchvision.models import resnet34

dls = ImageDataLoaders.from_folder("some/path/", train="train", valid="val", item_tfms=[Resize(224)])
learn = cnn_learner(dls, resnet34, metrics=[accuracy, Precision(), Recall(), F1Score()])
print(type(learn))  # fastai.learner.Learner
learn.lr_find()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_20462/2434377672.py in <module>
----> 1 learn.lr_find()

~/anaconda3/envs/doc-classif/lib/python3.8/site-packages/fastcore/basics.py in __getattr__(self, k)
    386         if self._component_attr_filter(k):
    387             attr = getattr(self,self._default,None)
--> 388             if attr is not None: return getattr(attr,k)
    389         raise AttributeError(k)
    390     def __dir__(self): return custom_dir(self,self._dir())

~/anaconda3/envs/doc-classif/lib/python3.8/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
   1128             if name in modules:
   1129                 return modules[name]
-> 1130         raise AttributeError("'{}' object has no attribute '{}'".format(
   1131             type(self).__name__, name))
   1132 

AttributeError: 'Sequential' object has no attribute 'lr_find'

Same for learn.fine_tune(). Am I doing something wrong ?

For the record I use the version 2.4.1, thank you very much for your help !

You’re using explicit imports when bringing everything in. fastai monkey patches many functions, so you should use the from fastai.vision.all import * style.

If you want an example of what all you need to really import to have access to all the methods, look at some of my notebooks on Walk with fastai, where I show what that is like. (It’s a lot)

1 Like

Okay that was one of the solution I had in mind but I didn’t know imports could work this way ! Thanks for your precious help @muellerzr !