Functions for handling images
References¶
Functions download_images
and verify_images
functions are based on the below sources. Please visit attached links for further understanding.
download_image
(dest
, url
, timeout
=5
)
Downloads an image from url to destination file path (pathlib.Path object).
Tries to detect and preserve original suffix and defaults to '.jpg' if none
Assigns a randomly generated filename to avoid name clashes.
Additional links on user agents to handle HTTP 406:
download_images
(url_file_path
, dest
, n_threads
=4
, timeout
=5
)
Downloads images from list of urls.
Makes use of multiprocessing library to support concurrent downloads if supported by CPU.
Visualizes progress using tqdm.
verify_image_tf
(img_file
)
Verifies if an image can be opened by tf.image module
tf.image currently supports only BMP, JPEG, GIF and PNG.
Function attempts to convert non-supported formats to JPEG.
If the image cannot be opened or converted, it is deleted.
verify_images
(file_path
, n_threads
=4
, recurse
=False
)
Verifies images from file path.
Makes use of multiprocessing library to support concurrent verification if supported by CPU.
Visualizes progress using tqdm.