mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import cv2
|
|
import pandas as pd
|
|
from deepface import DeepFace
|
|
from deepface.commons.logger import Logger
|
|
|
|
logger = Logger("tests/test_find.py")
|
|
|
|
|
|
def test_find_with_exact_path():
|
|
img_path = "dataset/img1.jpg"
|
|
dfs = DeepFace.find(img_path=img_path, db_path="dataset", silent=True)
|
|
assert len(dfs) > 0
|
|
for df in dfs:
|
|
assert isinstance(df, pd.DataFrame)
|
|
|
|
# one is img1.jpg itself
|
|
identity_df = df[df["identity"] == img_path]
|
|
assert identity_df.shape[0] > 0
|
|
|
|
# validate reproducability
|
|
assert identity_df["VGG-Face_cosine"].values[0] == 0
|
|
|
|
df = df[df["identity"] != img_path]
|
|
logger.debug(df.head())
|
|
assert df.shape[0] > 0
|
|
logger.info("✅ test find for exact path done")
|
|
|
|
|
|
def test_find_with_array_input():
|
|
img_path = "dataset/img1.jpg"
|
|
img1 = cv2.imread(img_path)
|
|
dfs = DeepFace.find(img1, db_path="dataset", silent=True)
|
|
assert len(dfs) > 0
|
|
for df in dfs:
|
|
assert isinstance(df, pd.DataFrame)
|
|
|
|
# one is img1.jpg itself
|
|
identity_df = df[df["identity"] == img_path]
|
|
assert identity_df.shape[0] > 0
|
|
|
|
# validate reproducability
|
|
assert identity_df["VGG-Face_cosine"].values[0] == 0
|
|
|
|
|
|
df = df[df["identity"] != img_path]
|
|
logger.debug(df.head())
|
|
assert df.shape[0] > 0
|
|
|
|
logger.info("✅ test find for array input done")
|