mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
Merge pull request #1127 from rezakarbasi/master
feat: an api test added. It evaluates inserting base64 encoded image
This commit is contained in:
commit
5d49679b19
@ -1,6 +1,7 @@
|
||||
import unittest
|
||||
from deepface.commons.logger import Logger
|
||||
from deepface.api.src.app import create_app
|
||||
import base64
|
||||
|
||||
|
||||
logger = Logger("tests/test_api.py")
|
||||
@ -77,6 +78,34 @@ class TestVerifyEndpoint(unittest.TestCase):
|
||||
|
||||
logger.info("✅ representation api test is done")
|
||||
|
||||
def test_represent_encoded(self):
|
||||
image_path = "dataset/img1.jpg"
|
||||
with open(image_path, "rb") as image_file:
|
||||
encoded_string = "data:image/jpeg;base64," + \
|
||||
base64.b64encode(image_file.read()).decode("utf8")
|
||||
|
||||
data = {
|
||||
"model_name": "Facenet",
|
||||
"detector_backend": "mtcnn",
|
||||
"img": encoded_string
|
||||
}
|
||||
|
||||
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"]) > 0
|
||||
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")
|
||||
|
||||
def test_analyze(self):
|
||||
data = {
|
||||
"img": "dataset/img1.jpg",
|
||||
|
Loading…
x
Reference in New Issue
Block a user