Merge pull request #1128 from rezakarbasi/master

2 tests regarding feeding different data sources added
This commit is contained in:
Sefik Ilkin Serengil 2024-03-20 10:38:09 +00:00 committed by GitHub
commit c774ca4c2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,7 +76,7 @@ class TestVerifyEndpoint(unittest.TestCase):
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"
@ -104,7 +104,30 @@ class TestVerifyEndpoint(unittest.TestCase):
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 = {
@ -127,6 +150,58 @@ class TestVerifyEndpoint(unittest.TestCase):
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",