Lesson 2 official topic

For Windows users, if you want to run the Hugging Face Space code locally without having to run Linux, you can add this before trying to load the model:

import os
if os.name != 'posix':
    import pathlib
    pathlib.PosixPath = pathlib.WindowsPath

learn = load_learner('model.pkl')

I’m having problems with ims = search_images_ddg(u'grizzly bear') in the grazzly bear data gathering when I try it on my localhost and/or Colab.
It gives my a “urlopen error, Connection timed out”.
I checked fastai github and find an open issue addressing the same problem. search_images_ddg always fails with TimeoutError · Issue #528 · fastai/fastbook · GitHub
So maybe I can try my luck here?

I have the same problem myself

Hey @RaviRaj988,
Remove the space before fastai in requirements.txt


If you want to run your Gradio app locally in a Python console (e.g. with PyCharm’s “Run with Python Console”) you’ll get an error like Can't get attribute 'is_cat' on <module '__main__' from ...

You can fix this by manually putting the function on the __main__ module:

def is_cat(x):
    return x[0].isupper()  # Used by model

import sys
sys.modules["__main__"].is_cat = is_cat

# Now import the model
1 Like

My first deployed model! It classifies pictures of barbells vs dumbells vs kettlebell. Very poor performance on confusion between barbell/dumbbell, but A-ok on differentiating kettlebells. A cutely trivial little case study in more and less challenging classes to identify.

Huge gratitude to you @jeremy for putting this out there. I am really inspired by the amazing tool that HF spaces is to deploy python functions (ML or not) to a wider end user audience and am trying to automate a business process via this tool now!

1 Like

Thank you, this helped a lot. On Chrome I did however run into a weird bug: when I tried to import from Github, it did not render the dropdown with the ipynb files in the repo correctly, and I could not select one.

After (unsuccessfully) messing with Chrome’s Inspector for a while, I tried to use the “Import from external URL” feature in Kaggle, instead of “Import from Github”. Pasting the URL to the ipynb on Github seems to have also successfully imported the notebook.

I was also running into the [None, None, …] problem with search_images_ddg. In case it’s helpful for anyone else, here is the code I ended up using for chapter 2, after @strickvl 's suggestion:

!pip install duckduckgo_search


from duckduckgo_search import ddg_images
from fastcore.all import *

def search_images(term, max_images=30):
    print(f"Searching for '{term}'")
    return L(ddg_images(term, max_results=max_images)).itemgot('image')


if True or not path.exists():
    for o in bear_types:
        dest = (path/o)
        results = search_images(f'{o} bear', max_images=3)
        download_images(dest, urls=results)

Not sure if I have missed some explanation somewhere about how to get search_images_ddg working properly.

I deployed my first app!
I would be happy if you would check it out for yourself.
An issue seems to be that it works muuuuch better with close up face portraits.
Check it out under the following link:
:slight_smile: or :frowning:


How do I access the dog vs cat notebook that has the python code for me to export? I exported the model in “Saving a basic fastai model” notebook but I can’t find the dogs vs cat notebook. I don’t see it anywhere in the links / resources sections.


You don’t mention whether you had watched Lesson 2, so try that… Lesson 2: Practical Deep Learning for Coders 2022 - YouTube

I did watch the lecture. Jordan is pulling up the notebook locally, so I’m not sure how I can access it.

I don’t know where you would find it without performing a search myself.
So since you seem to be stuck 2 days, can I suggest you try going old school? It really shouldn’t take more than twenty minutes to transcribe from the video - and often learning outcomes are better from typing examples yourself than just cut-n-pasting. HTH.

1 Like

If you look in chapter 2 of the fastbook: fastbook/02_production.ipynb at master · fastai/fastbook · GitHub

Scroll to “Turning Your Model into an Online Application” or just Ctrl + f search for “load_learner” you can find code that’s similar to what is occurring within the lecture.

For the most part this is true for all of the lessons, if you can’t fiind code, either look in the fastbook chapters, or the documentation. Here’s a link to the FastAI docs tutorial on training a computer vision model to detect cats vs dogs.

1 Like

Hi Tanishq, thanks fo rthe wonderful tutorial. I get this error at the end when of build
RuntimeError: Share is not supported when you are in Spaces

If the “share=True” is not included in launch() there is only a localhost address which I cannot access. Have I missed anything ?

Hi there,

As a complete beginner, I seem to have missed something that may seem obvious to others…

At 41:25 Jeremy says “So we’ve got a notebook for that”, and suddenly switches to a localhost tab.

Where can we find the “notebook for that”?

I tried searching the code but found it nowhere.

Thanks a lot for your help!

(Of course transcribing it directly could work and I’m prepared to do it myself but if a link exists it would be helpful for future learners to have it as part of resources for this course. Otherwise the risk is some will get stuck / give up etc.)


The notebooks are usually linked to in the course page. Also, what helped me was learning that I could clone the github fastbook pages into Kaggle: on Kaggle, choose File > Import, and then copy-paste the ipynb fastbook chapter. Hope that helps.

They’re meant to always be linked from there, in fact! So if you find one missing, please do tell me.

Hi all!

I’m excited to be finally running the notebooks after having watched the course a couple of times :slight_smile:
However I have hit on an error I can’t find a solution for. I’m using a free Paperspace account, and not sure I should be asking here? Since this is most likely this is a Paperspace-related issue.

But, it’s occurring in the Lesson 2: When calling the ‘ImageClassifierCleaner’: Paperspace errors with the message ‘Cannot read properties of undefined (reading ‘sessionContext’)’.

Here’s what I get when I ‘click to show the error message’:

The console really isn’t any help:

I’ve disabled any ad blockers and rerun the script, thinking that it might be blocking sessionContext, and also restarted and retried a bunch of times, but can’t think what else to try? Should I reach out to paperspace support?

Not sure how to proceed, since it’s not letting me clean the errors in my model.


Here’s the 50/50 catdog talked about in the class! :rofl: