In chapter 2 of the Deep Learning for Coders book (and lesson 3 of the course) we show how to download images with the Bing Image Search API.
You can get more information about this API from the official website. If you're having trouble signing up for the service, there is some more information on the forum.
Additionally, here is a video which walks you through the process of getting the api keys:
Alternatively, you can use DuckDuckGo instead of Bing. DuckDuckGo is a "privacy first" search service, with many useful features. However, they do not have an official API, so the function we'll show here relies on the particular structure of their web interface, which may change.
To use DuckDuckGo to download images, use the search_images_ddg
function from fastbook
, like so:
from fastbook import *
urls = search_images_ddg('grizzly bear', max_images=100)
len(urls),urls[0]
The URLs are returned as strings, so you won't need the attrgot
line that's in the book:
download_url(urls[0], 'images/bear.jpg')
im = Image.open('images/bear.jpg')
im.thumbnail((256,256))
im