mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 11:35:21 +00:00
list_images now stores valid image and PIL exts in sets built ahead of time rather than on each iteration. exact_path is not created unless the file's ext is a valid image ext.
This commit is contained in:
parent
fea8b11cf5
commit
ca9ecbb3ca
@ -23,18 +23,15 @@ def list_images(path: str) -> List[str]:
|
|||||||
images (list): list of exact image paths
|
images (list): list of exact image paths
|
||||||
"""
|
"""
|
||||||
images = []
|
images = []
|
||||||
|
image_exts = {".jpg", ".jpeg", ".png"}
|
||||||
|
pil_exts = {"jpeg", "png"}
|
||||||
for r, _, f in os.walk(path):
|
for r, _, f in os.walk(path):
|
||||||
for file in f:
|
for file in f:
|
||||||
exact_path = os.path.join(r, file)
|
if os.path.splitext(file)[1].lower() in image_exts:
|
||||||
|
exact_path = os.path.join(r, file)
|
||||||
ext_lower = os.path.splitext(exact_path)[-1].lower()
|
with Image.open(exact_path) as img: # lazy
|
||||||
|
if img.format.lower() in pil_exts:
|
||||||
if ext_lower not in {".jpg", ".jpeg", ".png"}:
|
images.append(exact_path)
|
||||||
continue
|
|
||||||
|
|
||||||
with Image.open(exact_path) as img: # lazy
|
|
||||||
if img.format.lower() in {"jpeg", "png"}:
|
|
||||||
images.append(exact_path)
|
|
||||||
return images
|
return images
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user