mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 19:45:21 +00:00
opencv
This commit is contained in:
parent
d1e91faa3f
commit
a152bd734e
121
api/app.py
Normal file
121
api/app.py
Normal file
@ -0,0 +1,121 @@
|
||||
from flask import Flask, jsonify, request, make_response
|
||||
|
||||
import uuid
|
||||
import json
|
||||
import time
|
||||
|
||||
from deepface import DeepFace
|
||||
|
||||
#------------------------------
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
#------------------------------
|
||||
#Service API Interface
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return '<h1>Hello, world!</h1>'
|
||||
|
||||
@app.route('/analyze', methods=['POST'])
|
||||
def analyze():
|
||||
|
||||
req = request.get_json()
|
||||
trx_id = uuid.uuid4()
|
||||
|
||||
#---------------------------
|
||||
|
||||
tic = time.time()
|
||||
|
||||
instances = []
|
||||
if "img" in list(req.keys()):
|
||||
raw_content = req["img"] #list
|
||||
|
||||
for item in raw_content: #item is in type of dict
|
||||
instances.append(item)
|
||||
|
||||
if len(instances) == 0:
|
||||
return jsonify({'success': False, 'error': 'you must pass at least one img object in your request'}), 205
|
||||
|
||||
print("Analyzing ", len(instances)," instances")
|
||||
|
||||
#---------------------------
|
||||
|
||||
actions= ['emotion', 'age', 'gender', 'race']
|
||||
if "actions" in list(req.keys()):
|
||||
actions = req["actions"]
|
||||
|
||||
#---------------------------
|
||||
|
||||
resp_obj = DeepFace.analyze(instances, actions=actions)
|
||||
|
||||
#---------------------------
|
||||
|
||||
toc = time.time()
|
||||
|
||||
resp_obj["trx_id"] = trx_id
|
||||
resp_obj["seconds"] = toc-tic
|
||||
|
||||
return resp_obj
|
||||
|
||||
@app.route('/verify', methods=['POST'])
|
||||
|
||||
def verify():
|
||||
|
||||
req = request.get_json()
|
||||
trx_id = uuid.uuid4()
|
||||
|
||||
tic = time.time()
|
||||
|
||||
#-------------------------
|
||||
|
||||
model_name = "VGG-Face"; distance_metric = "cosine"
|
||||
if "model_name" in list(req.keys()):
|
||||
model_name = req["model_name"]
|
||||
if "distance_metric" in list(req.keys()):
|
||||
distance_metric = req["distance_metric"]
|
||||
|
||||
instances = []
|
||||
if "img" in list(req.keys()):
|
||||
raw_content = req["img"] #list
|
||||
|
||||
for item in raw_content: #item is in type of dict
|
||||
instance = []
|
||||
img1 = item["img1"]; img2 = item["img2"]
|
||||
|
||||
validate_img1 = False
|
||||
if len(img1) > 11 and img1[0:11] == "data:image/":
|
||||
validate_img1 = True
|
||||
|
||||
validate_img2 = False
|
||||
if len(img2) > 11 and img2[0:11] == "data:image/":
|
||||
validate_img2 = True
|
||||
|
||||
if validate_img1 != True or validate_img2 != True:
|
||||
return jsonify({'success': False, 'error': 'you must pass both img1 and img2 as base64 encoded string'}), 205
|
||||
|
||||
instance.append(img1); instance.append(img2)
|
||||
instances.append(instance)
|
||||
|
||||
#--------------------------
|
||||
|
||||
if len(instances) == 0:
|
||||
return jsonify({'success': False, 'error': 'you must pass at least one img object in your request'}), 205
|
||||
|
||||
print("Input request of ", trx_id, " has ",len(instances)," pairs to verify")
|
||||
|
||||
#--------------------------
|
||||
resp_obj = DeepFace.verify(instances, model_name = model_name, distance_metric = distance_metric)
|
||||
|
||||
toc = time.time()
|
||||
|
||||
resp_obj["trx_id"] = trx_id
|
||||
resp_obj["seconds"] = toc-tic
|
||||
|
||||
#--------------------------
|
||||
|
||||
return resp_obj, 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
app.run()
|
137
api/postman/deepface.postman_collection.json
Normal file
137
api/postman/deepface.postman_collection.json
Normal file
File diff suppressed because one or more lines are too long
4
setup.py
4
setup.py
@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
||||
|
||||
setuptools.setup(
|
||||
name="deepface",
|
||||
version="0.0.15",
|
||||
version="0.0.16",
|
||||
author="Sefik Ilkin Serengil",
|
||||
author_email="serengil@gmail.com",
|
||||
description="Deep Face Analysis Framework for Face Recognition and Demography",
|
||||
@ -19,5 +19,5 @@ setuptools.setup(
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
python_requires='>=3.5.5',
|
||||
install_requires=["numpy>=1.14.0", "pandas>=0.23.4", "tqdm>=4.30.0", "gdown>=3.10.1", "opencv-python>=3.4.4", "Pillow>=5.2.0", "tensorflow>=1.9.0", "keras>=2.2.0"]
|
||||
install_requires=["numpy>=1.14.0", "pandas>=0.23.4", "tqdm>=4.30.0", "gdown>=3.10.1", "Pillow>=5.2.0", "tensorflow>=1.9.0", "keras>=2.2.0"]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user