Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 tests regarding feeding different data sources added #1128

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_represent(self):
assert i.get("face_confidence") is not None
assert i.get("facial_area") is not None

logger.info("✅ representation api test is done")
logger.info("✅ representation api test is done (for image path)")

def test_represent_encoded(self):
image_path = "dataset/img1.jpg"
Expand Down Expand Up @@ -104,7 +104,30 @@ def test_represent_encoded(self):
assert i.get("face_confidence") is not None
assert i.get("facial_area") is not None

logger.info("✅ representation api test is done")
logger.info("✅ representation api test is done (for encoded image)")

def test_represent_url(self):
data = {
"model_name": "Facenet",
"detector_backend": "mtcnn",
"img": "https://github.com/serengil/deepface/blob/master/tests/dataset/couple.jpg?raw=true"
}

response = self.app.post("/represent", json=data)
assert response.status_code == 200
result = response.json
logger.debug(result)
assert result.get("results") is not None
assert isinstance(result["results"], list) is True
assert len(result["results"]) == 2 # 2 faces are in the image link
for i in result["results"]:
assert i.get("embedding") is not None
assert isinstance(i.get("embedding"), list) is True
assert len(i.get("embedding")) == 128
assert i.get("face_confidence") is not None
assert i.get("facial_area") is not None

logger.info("✅ representation api test is done (for image url)")

def test_analyze(self):
data = {
Expand All @@ -127,6 +150,58 @@ def test_analyze(self):

logger.info("✅ analyze api test is done")

def test_analyze_inputformats(self):
image_path = "dataset/couple.jpg"
with open(image_path, "rb") as image_file:
encoded_image = "data:image/jpeg;base64," + \
base64.b64encode(image_file.read()).decode("utf8")

image_sources = [
# image path
image_path,
# image url
f"https://github.com/serengil/deepface/blob/master/tests/{image_path}?raw=true",
# encoded image
encoded_image
]

results = []
for img in image_sources:
data = {
"img": img,
}
response = self.app.post("/analyze", json=data)

assert response.status_code == 200
result = response.json
results.append(result)

assert result.get("results") is not None
assert isinstance(result["results"], list) is True
assert len(result["results"]) > 0
for i in result["results"]:
assert i.get("age") is not None
assert isinstance(i.get("age"), (int, float))
assert i.get("dominant_gender") is not None
assert i.get("dominant_gender") in ["Man", "Woman"]
assert i.get("dominant_emotion") is not None
assert i.get("dominant_race") is not None

assert len(results[0]["results"]) == len(results[1]["results"])\
and len(results[0]["results"]) == len(results[2]["results"])

for i in range(len(results[0]['results'])):
assert results[0]["results"][i]["dominant_emotion"] == results[1]["results"][i]["dominant_emotion"]\
and results[0]["results"][i]["dominant_emotion"] == results[2]["results"][i]["dominant_emotion"]

assert results[0]["results"][i]["dominant_gender"] == results[1]["results"][i]["dominant_gender"]\
and results[0]["results"][i]["dominant_gender"] == results[2]["results"][i]["dominant_gender"]

assert results[0]["results"][i]["dominant_race"] == results[1]["results"][i]["dominant_race"]\
and results[0]["results"][i]["dominant_race"] == results[2]["results"][i]["dominant_race"]

logger.info("✅ different inputs test is done")

def test_invalid_verify(self):
data = {
"img1_path": "dataset/invalid_1.jpg",
Expand Down