Search code examples
fast-ai

Fast Ai: AttributeError: 'Learner' object has no attribute 'fine_tune'


Fast Ai uses a very unconventional style of from fastai import * etc.

I for one do not like it so was painstakingly identifying each import in the chapter 2 of the fastai book but ran into the error

AttributeError: 'Learner' object has no attribute 'fine_tune'

However, when I then go and do

from fastbook import *

it works. This is a very odd behavior in that something is done to the cnn_learner class or the module that contains it making it have the fine_tune method if the above import is done.

I would like to avoid this style of coding, so what should I do to load the correct version of Learner?


Solution

  • I just faced the exact same issue. After looking at one of their tutorial I saw that the cnn learner is not imported from the expected package.

    from fastai.vision.all import cnn_learner
    # rather than
    from fastai.vision.learner import cnn_learner
    

    calling the fine_tune method then works as expected !