Skip to content

Sample Image Downloader

download(keywords, type='face', limit=20, output_directory='/home/runner/work/facereg/facereg/datasets')

Download images from Google with given parameters.

Parameters:

Name Type Description Default
keywords str

Keywords to download images.

required
type str

Denotes the type of image to be downloaded. Default face.

'face'
limit int

Maximum number of images to be downloaded. Default 20 and max 100.

20
output_directory str

Directory name in which the images are downloaded.

'/home/runner/work/facereg/facereg/datasets'

Returns:

Type Description
Tuple[Dict, str]

paths (dictionary), errors (str): Image paths that has downloaded images.

Source code in facereg/google_images.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def download(
    keywords, type="face", limit=20, output_directory=output_directory
) -> Tuple[Dict, str]:
    """Download images from Google with given parameters.
    Args:
      keywords (str):
        Keywords to download images.
      type (str):
        Denotes the type of image to be downloaded. Default `face`.
      limit (int):
        Maximum number of images to be downloaded. Default `20` and max `100`.
      output_directory (str):
        Directory name in which the images are downloaded.
    Returns:
      paths (dictionary), errors (str):
        Image paths that has downloaded images.
    """

    downloader = google_images_download.googleimagesdownload()
    arguments = {
        "keywords": keywords,
        "limit": limit,
        "output_directory": output_directory,
        "print_urls": True,
        "type": type,
    }
    paths, errors = downloader.download(arguments)
    return paths, errors