From 83031a427d29322d9476e939c45bca7f6d303724 Mon Sep 17 00:00:00 2001 From: "Samuel J. Woodward" Date: Tue, 7 Jan 2025 10:25:40 -0500 Subject: [PATCH] image_exts and pil_exts are now global variables and are now named as IMAGE_EXTS and PIL_EXTS to match Python naming conventions. --- deepface/commons/image_utils.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/deepface/commons/image_utils.py b/deepface/commons/image_utils.py index b984f91..868eaf2 100644 --- a/deepface/commons/image_utils.py +++ b/deepface/commons/image_utils.py @@ -14,6 +14,10 @@ from PIL import Image from werkzeug.datastructures import FileStorage +IMAGE_EXTS = {".jpg", ".jpeg", ".png"} +PIL_EXTS = {"jpeg", "png"} + + def list_images(path: str) -> List[str]: """ List images in a given path @@ -23,14 +27,12 @@ def list_images(path: str) -> List[str]: images (list): list of exact image paths """ images = [] - image_exts = {".jpg", ".jpeg", ".png"} - pil_exts = {"jpeg", "png"} for r, _, f in os.walk(path): for file in f: - if os.path.splitext(file)[1].lower() in image_exts: + if os.path.splitext(file)[1].lower() in IMAGE_EXTS: exact_path = os.path.join(r, file) with Image.open(exact_path) as img: # lazy - if img.format.lower() in pil_exts: + if img.format.lower() in PIL_EXTS: images.append(exact_path) return images @@ -43,14 +45,12 @@ def yield_images(path: str) -> Generator[str, None, None]: Yields: image (str): image path """ - image_exts = {".jpg", ".jpeg", ".png"} - pil_exts = {"jpeg", "png"} for r, _, f in os.walk(path): for file in f: - if os.path.splitext(file)[1].lower() in image_exts: + if os.path.splitext(file)[1].lower() in IMAGE_EXTS: exact_path = os.path.join(r, file) with Image.open(exact_path) as img: # lazy - if img.format.lower() in pil_exts: + if img.format.lower() in PIL_EXTS: yield exact_path