How to download images without the javascript trick (Lesson2)

Goal : download google images from your notebook (locally, Colab, etc…) using python
TLDR: run the commands in bold here below

Some people are having trouble downloading google images using the javascript trick showed in Lesson2 (Part1) in the lesson2-download.ipynb notebook.

There is an easier way to download google images using the google-images-download python module in your jupyter notebook.

Here are the steps to download the different bears images

First install the python module. In a cell, enter the following command
!pip install google_images_download

Then in the subsequent cells, start downloadig the grizzly bears (-k grizzly argument below)
!googleimagesdownload -k grizzly -l 100
A new folder called downloads/grizzly will be created with 100 images in it (that’s the -l 100 argument n the command above)

Do the same thing for the other images
!googleimagesdownload -k ‘black bear’ -l 100
!googleimagesdownload -k ‘teddy bear’ -l 100

Run the ls command
!ls downloads/
and you should have the 3 following folders
‘black bear’ grizzly ‘teddy bear’

If you are using the lesson2-download, you can update your path like this (assuming you are using Colab)
classes = [‘grizzly’, ‘black bear’, ‘teddy bear’]
path = Path(’/content/downloads’)
path.ls()

The cell output should look like this
[PosixPath(’/content/downloads/grizzly’),
PosixPath(’/content/downloads/black bear’),
PosixPath(’/content/downloads/teddy bear’)]

From there, you can just continue executing the rest of the cells.

If you want to keep the original folder names (used in lesson2-download.ipynb) you can rename the new folder names listed here above to match those of lesson2-download.ipynb notebook.

Have fun creating your own classifier!

4 Likes

Thank you! For some reason, I’m getting 0 is all we got for this search filter! for !googleimagesdownload -k grizzly -l 100.
http://prntscr.com/rfbl90

How can I fix it? (I’m using Colab)

There are many people who seem to experience the same issue. You might want to check this post where Greg proposed a solution in the post quoted below:

4 Likes

Thank you Farid!

1 Like