Skip to content

Commit

Permalink
image_exts and pil_exts are now global variables and are now named as…
Browse files Browse the repository at this point in the history
… IMAGE_EXTS and PIL_EXTS to match Python naming conventions.
  • Loading branch information
PyWoody committed Jan 7, 2025
1 parent 6a75052 commit 83031a4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions deepface/commons/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
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
Expand All @@ -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

Expand All @@ -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


Expand Down

0 comments on commit 83031a4

Please sign in to comment.