course20 icon indicating copy to clipboard operation
course20 copied to clipboard

image_cat() not defined error

Open sumitpowar opened this issue 4 years ago • 3 comments

HI,

What is image_cat() in the following code (given in lesson 1)?

img = PILImage.create(image_cat()) img.to_thumb(192)

It gives following error after running it:

**NameError Traceback (most recent call last) in ----> 1 img = PILImage.create(image_cat()) 2 img.to_thumb(192)

NameError: name 'image_cat' is not defined**

sumitpowar avatar Apr 23 '21 17:04 sumitpowar

make sure you import * from fastbook image_cat is a function that returns a sample cat image built into the fast.ai lib

import fastbook
fastbook.setup_book()
from fastbook import *

venomoustoad avatar Jun 04 '21 07:06 venomoustoad

thanks, venomoustoad!

I had the same issue. This one line: from fastbook import * fixes NameError mentioned by sumitpowar above:

from fastbook import *
img1 = PILImage.create(image_cat())
img1.to_thumb(192)

The course page may benefit from this modification.

Best, PO

PO20 avatar Jul 17 '21 08:07 PO20

Still doesn't work. Neither does: from fastai import *

Turns out that you can corrupt a Kaggle notebook with the wrong imports. Starting from scratch and this works: ! pip install -Uqq fastbook import fastbook fastbook.setup_book() from fastbook import * img = PILImage.create(image_cat()) img.to_thumb(192)

jasondeegan avatar Jun 13 '23 00:06 jasondeegan