Update: Bug fixed by the library developer!

Dear Students,

There is a bug in an external library making the searches fail when searching for the same term twice within a short time in 00-is-it-a-bird-creating-a-model-from-your-own-data.ipynb from fastai/course22. 

This a known issue in the fastai forum that has just happened in the last week or two. It can be fixed as follows.

Here is the solution I just tested.

First make sure you have fastbook installed as we will use the search_images_ddg function from there.

At the terminal type pip install fastbook.

Now fetch search_images_ddg from fastbook.

After the line Let’s start by searching for a bird photo and seeing what kind of result we get. We’ll start by getting URLs from a search: we fix the cell by replacing it with:

from fastbook import search_images_ddg
urls = search_images_ddg('bird photos', max_images=1)
urls[0]

After this line Now let’s do the same with “forest photos”: we fix the cell by replacing it with:

download_url(search_images_ddg('forest photos', max_images=1)[0], 'forest.jpg', show_progress=False)
Image.open('forest.jpg').to_thumb(256,256)

Finally we fix the cell after Our searches seem to be giving reasonable results, so let’s grab 200 examples of each of “bird” and “forest” photos, and save each group of photos to a different folder: by replacing it with:

searches = 'forest','bird'
path = Path('bird_or_not')
from time import sleep

for o in searches:
    dest = (path/o)
    dest.mkdir(exist_ok=True, parents=True)
    download_images(dest, urls=search_images_ddg(f'{o} photo'))
    sleep(10)  # Pause between searches to avoid over-loading server
    download_images(dest, urls=search_images_ddg(f'{o} sun photo'))
    sleep(10)
    download_images(dest, urls=search_images_ddg(f'{o} shade photo'))
    sleep(10)
    resize_images(path/o, max_size=400, dest=path/o)

This should fix all the searches.

Happy fastai-ing,

Brian

Brian Lovell Portrait