Some utils function to quickly download a bunch of images, check them and pre-resize them
path = untar_data(URLs.IMAGENETTE)
path
Path('/home/jhoward/.fastai/data/imagenette2')
with tempfile.TemporaryDirectory() as d:
    d = Path(d)
    url = "https://www.fast.ai/images/jh-head"
    _download_image_inner(d, (125,url))
    assert (d/'00000125.jpg').is_file()

download_images[source]

download_images(dest, url_file=None, urls=None, max_pics=1000, n_workers=8, timeout=4)

Download images listed in text file url_file to path dest, at most max_pics

with tempfile.TemporaryDirectory() as d:
    d = Path(d)
    url_file = d/'urls.txt'
    url_file.write("\n".join([f"https://www.fast.ai/images/{n}" for n in "jh-head thomas.JPG sg-head".split()]))
    download_images(d, url_file)
    for i in [0,2]: assert (d/f'0000000{i}.jpg').is_file()
    assert (d/f'00000001.JPG').is_file()

resize_to[source]

resize_to(img, targ_sz, use_min=False)

Size to resize to, to hit targ_sz at same aspect ratio, in PIL coords (i.e w*h)

class _FakeImg():
    def __init__(self, size): self.size=size
img = _FakeImg((200,500))

test_eq(resize_to(img, 400), [160,400])
test_eq(resize_to(img, 400, use_min=True), [400,1000])

verify_image[source]

verify_image(fn)

Confirm that fn can be opened

verify_images[source]

verify_images(fns)

Find images in fns that can't be opened