Lesson 1: NameError: name 'cnn_learner' is not defined


I am getting the following error in Lesson 1


1 Like

Hey @velidia
I got the same error a while ago.
My version of fastai is 1.0.46
I checked list of methods available for fastai.vision using dir(), and figured out that the method available to create CNN learner is create _cnn, and not cnn_learner.
I tried the same and overcame the error. It’s working now.
So go ahead and replace cnn_learner with create _cnn

Cheers !


This is the correct answer. You can find breaking changes on the fastai v1 GitHub page under “changes”

There is also a topic with all the announcements you should follow

1 Like

Hey shahbazkhan185,
Changing cnn_learner to create_cnn worked. Thanks!


Better use:
!pip install --no-deps fastai==1.0.47 to grab the version where it works, or later version.

Adding ‘deprecated’ messages and supporting the old and the new version, at least for refactorings in terms of naming, are in general a good way to prevent such problems.

The message will then tell you, what changed, so that you can adapt the code.

1 Like

@sgugger I believe that’s backwards in the .md file:

1.0.47 (2019-03-06)

Breaking changes:

  • create_cnn becomes cnn_learner

Shouldn’t it be

  • cnn_learner becomes create_cnn

If so let me know if you’d like to me to create a branch and a PR for this

No, it’s the right way: there is no create_cnn anymore, and it’s cnn_learner that should be used.

Errr… that’s the opposite of my experience just now, and what the others above seem to be saying. Unless I should do a pull/update, which I’ll try.

Yes create_cnn works instead of cnn_learner.

If create_cnn works you have an older version of fastai installed. In the current version of fastai it’s cnn_learner

Well I figured this out. It has to do with git pull not updating correctly. I first tried

cd course-v3
git pull

and it did update some files. However, it still only worked with create_cnn (even after shutting down and restarting the paperspace machine).

I then looked at the conda tab in the Jupyter notebook:


So I went to /opt/conda/envs/fastai in a new terminal window

From within that folder I ran:

conda install -c fastai fastai

After the installation I launched python with the python3 command. I was then able to run

import fastai; fastai.__version__

and the version which had been 1.0.42 is now showing as 1.0.50.

Running the notebook confirmed that create_cnn no longer works, and cnn_learner does work.

(Note to admin: some of this I’ve duplicated from the paperspace thread; there were related questions both here and there).

I confirm this works, thanks for the help

Hi @sgugger, I have fastai version 1.0.42. Even then create_cnn works and not cnn_learner. Am I missing anything. I took a fastai vm on paperspace for this course. Please help

1 Like

As explained before, you should update your fastai install to v1.0.47 or later. Click on the relevant provider in the returning to work tab of this page to know how.

1 Like

Hey @sgugger,
Thanks for the help. This is how I did it . used pip install fastai --upgrade and now my fastai version is 1.0.54 and things work as mentioned in video tutorial . Thanks @sgugger

1 Like

con base en la version de fast ia cualquera de ellos funciona, a mi me funciona cnn_learner ya que tengo la ultima version