mirror of
https://github.com/serengil/deepface.git
synced 2025-06-11 05:47:08 +00:00
Use path join and amend undetected faces addition repetition
This commit is contained in:
parent
c4b48ce46f
commit
72e5669302
@ -99,7 +99,7 @@ def find(
|
|||||||
|
|
||||||
file_name = f"representations_{model_name}.pkl"
|
file_name = f"representations_{model_name}.pkl"
|
||||||
file_name = file_name.replace("-", "_").lower()
|
file_name = file_name.replace("-", "_").lower()
|
||||||
datastore_path = f"{db_path}/{file_name}"
|
datastore_path = os.path.join(db_path, file_name)
|
||||||
|
|
||||||
df_cols = [
|
df_cols = [
|
||||||
"identity",
|
"identity",
|
||||||
@ -162,7 +162,7 @@ def find(
|
|||||||
logger.info(
|
logger.info(
|
||||||
f"{len(newbies)} new representations are just added"
|
f"{len(newbies)} new representations are just added"
|
||||||
f" whereas {len(oldies)} represented one(s) are just dropped"
|
f" whereas {len(oldies)} represented one(s) are just dropped"
|
||||||
f" in {db_path}/{file_name} file."
|
f" in {os.path.join(db_path,file_name)} file."
|
||||||
)
|
)
|
||||||
|
|
||||||
if not silent:
|
if not silent:
|
||||||
@ -173,8 +173,8 @@ def find(
|
|||||||
|
|
||||||
if len(employees) == 0:
|
if len(employees) == 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"There is no image in {db_path} folder!"
|
f"Could not find any valid image in {db_path} folder!"
|
||||||
"Validate .jpg, .jpeg or .png files exist in this path.",
|
"Valid images are .jpg, .jpeg or .png files.",
|
||||||
)
|
)
|
||||||
|
|
||||||
# ------------------------
|
# ------------------------
|
||||||
@ -196,7 +196,7 @@ def find(
|
|||||||
pickle.dump(representations, f)
|
pickle.dump(representations, f)
|
||||||
|
|
||||||
if not silent:
|
if not silent:
|
||||||
logger.info(f"Representations stored in {db_path}/{file_name} file.")
|
logger.info(f"Representations stored in {datastore_path} file.")
|
||||||
|
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# now, we got representations for facial database
|
# now, we got representations for facial database
|
||||||
@ -241,6 +241,9 @@ def find(
|
|||||||
distances = []
|
distances = []
|
||||||
for _, instance in df.iterrows():
|
for _, instance in df.iterrows():
|
||||||
source_representation = instance[f"{model_name}_representation"]
|
source_representation = instance[f"{model_name}_representation"]
|
||||||
|
if source_representation is None:
|
||||||
|
distances.append(float("inf")) # no representation for this image
|
||||||
|
continue
|
||||||
|
|
||||||
target_dims = len(list(target_representation))
|
target_dims = len(list(target_representation))
|
||||||
source_dims = len(list(source_representation))
|
source_dims = len(list(source_representation))
|
||||||
@ -292,7 +295,7 @@ def find(
|
|||||||
return resp_obj
|
return resp_obj
|
||||||
|
|
||||||
|
|
||||||
def __list_images(path: str) -> list:
|
def __list_images(path: str) -> list[str]:
|
||||||
"""
|
"""
|
||||||
List images in a given path
|
List images in a given path
|
||||||
Args:
|
Args:
|
||||||
@ -304,7 +307,7 @@ def __list_images(path: str) -> list:
|
|||||||
for r, _, f in os.walk(path):
|
for r, _, f in os.walk(path):
|
||||||
for file in f:
|
for file in f:
|
||||||
if file.lower().endswith((".jpg", ".jpeg", ".png")):
|
if file.lower().endswith((".jpg", ".jpeg", ".png")):
|
||||||
exact_path = f"{r}/{file}"
|
exact_path = os.path.join(r, file)
|
||||||
images.append(exact_path)
|
images.append(exact_path)
|
||||||
return images
|
return images
|
||||||
|
|
||||||
@ -365,31 +368,35 @@ def __find_bulk_embeddings(
|
|||||||
expand_percentage=expand_percentage,
|
expand_percentage=expand_percentage,
|
||||||
)
|
)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
logger.warn(
|
logger.error(
|
||||||
f"Exception while extracting faces from {employee}: {str(err)}. Skipping it."
|
f"Exception while extracting faces from {employee}: {str(err)}"
|
||||||
)
|
)
|
||||||
img_objs = []
|
img_objs = []
|
||||||
|
|
||||||
for img_obj in img_objs:
|
if len(img_objs) == 0:
|
||||||
img_content = img_obj["face"]
|
logger.warn(f"No face detected in {employee}. It will be skipped in detection.")
|
||||||
img_region = img_obj["facial_area"]
|
representations.append((employee, None, 0, 0, 0, 0))
|
||||||
embedding_obj = representation.represent(
|
else:
|
||||||
img_path=img_content,
|
for img_obj in img_objs:
|
||||||
model_name=model_name,
|
img_content = img_obj["face"]
|
||||||
enforce_detection=enforce_detection,
|
img_region = img_obj["facial_area"]
|
||||||
detector_backend="skip",
|
embedding_obj = representation.represent(
|
||||||
align=align,
|
img_path=img_content,
|
||||||
normalization=normalization,
|
model_name=model_name,
|
||||||
)
|
enforce_detection=enforce_detection,
|
||||||
|
detector_backend="skip",
|
||||||
|
align=align,
|
||||||
|
normalization=normalization,
|
||||||
|
)
|
||||||
|
|
||||||
img_representation = embedding_obj[0]["embedding"]
|
img_representation = embedding_obj[0]["embedding"]
|
||||||
|
representations.append((
|
||||||
|
employee,
|
||||||
|
img_representation,
|
||||||
|
img_region["x"],
|
||||||
|
img_region["y"],
|
||||||
|
img_region["w"],
|
||||||
|
img_region["h"]
|
||||||
|
))
|
||||||
|
|
||||||
instance = []
|
|
||||||
instance.append(employee)
|
|
||||||
instance.append(img_representation)
|
|
||||||
instance.append(img_region["x"])
|
|
||||||
instance.append(img_region["y"])
|
|
||||||
instance.append(img_region["w"])
|
|
||||||
instance.append(img_region["h"])
|
|
||||||
representations.append(instance)
|
|
||||||
return representations
|
return representations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user