To download images with Bing Image Search, sign up at Microsoft for a free account. You will be given a key, which you can copy and enter in a cell as follows (replacing 'XXX' with your key and executing it):

search_images_bing
results = search_images_bing(key, 'Betta Fish')
ims = results.attrgot('content_url')
len(ims)
150
ims[0]
'https://upload.wikimedia.org/wikipedia/commons/1/16/Mimus_polyglottos1.jpg'
Here I have to make a directory for images.  I kept getting an error, but found the solution on the forums
https://forums.fast.ai/t/2020-lesson-2-02-production-filenotfounderror-images-grizzly-jpg/77348
import os
os.mkdir('images')
dest = 'images/betta1.jpg'
download_url(ims[0], dest)
im = Image.open(dest)
im.to_thumb(128,128)
fish_types = 'Betta Fish','Goldfish','clownfish'
path = Path('fishes') #make the directory plural
if not path.exists():
    path.mkdir()
    for o in fish_types:
        dest = (path/o)
        dest.mkdir(exist_ok=True)
        results = search_images_bing(key, f'{o}') #note that I took out the "fish" and put it in the fish_types
        download_images(dest, urls=results.attrgot('content_url'))
fns = get_image_files(path)
fns
(#446) [Path('fishes/Betta Fish/00000004.jpg'),Path('fishes/Betta Fish/00000005.jpg'),Path('fishes/Betta Fish/00000000.jpg'),Path('fishes/Betta Fish/00000001.jpg'),Path('fishes/Betta Fish/00000006.jpg'),Path('fishes/Betta Fish/00000010.jpg'),Path('fishes/Betta Fish/00000007.jpg'),Path('fishes/Betta Fish/00000008.jpg'),Path('fishes/Betta Fish/00000009.jpg'),Path('fishes/Betta Fish/00000003.jpg')...]
failed = verify_images(fns)
failed
(#0) []
failed.map(Path.unlink);

Sidebar: Getting Help in Jupyter Notebooks

End sidebar

From Data to DataLoaders

#ok, I admit, I got lazy here and didn't change the names, but it ran just fine

bears = DataBlock(
    blocks=(ImageBlock, CategoryBlock), 
    get_items=get_image_files, 
    splitter=RandomSplitter(valid_pct=0.2, seed=42),
    get_y=parent_label,
    item_tfms=Resize(128))
dls = bears.dataloaders(path)
dls.valid.show_batch(max_n=4, nrows=1)
bears = bears.new(item_tfms=Resize(128, ResizeMethod.Squish))
dls = bears.dataloaders(path)
dls.valid.show_batch(max_n=4, nrows=1)
bears = bears.new(item_tfms=Resize(128, ResizeMethod.Pad, pad_mode='zeros'))
dls = bears.dataloaders(path)
dls.valid.show_batch(max_n=4, nrows=1)
bears = bears.new(item_tfms=RandomResizedCrop(128, min_scale=0.3))
dls = bears.dataloaders(path)
dls.train.show_batch(max_n=4, nrows=1, unique=True)

Data Augmentation

bears = bears.new(item_tfms=Resize(128), batch_tfms=aug_transforms(mult=2))
dls = bears.dataloaders(path)
dls.train.show_batch(max_n=8, nrows=2, unique=True)