Last active
June 7, 2021 06:14
-
-
Save punsisi2018861/a640e4c05e74474c8561c1423b06eca4 to your computer and use it in GitHub Desktop.
Deepface Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
from deepface import DeepFace | |
import matplotlib.pyplot as plt | |
import os | |
from minio import Minio | |
app = Flask(__name__) | |
# allow POST requests | |
@app.route('/faceSimilarity', methods=['POST']) | |
def faceCompare(): | |
data = request.get_json() | |
img1 = data['img1'] | |
img2 = data['img2'] | |
result = verification(img1,img2) | |
return jsonify(result) | |
if __name__ == '__main__': | |
app.run() | |
def verification(img1, img2, max_threshold_to_verify=0.35, model_name="VGG-Face", | |
distance_metric="cosine"): | |
output = {} | |
# Connecting to minio server | |
client = Minio('play.minio.io:9000', | |
access_key='Q3AM3UQ867SPQQA43P2F', | |
secret_key='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG', | |
secure=True) | |
# Downloading the images to VM | |
client.fget_object("img", img1, img1) | |
client.fget_object("img", img2, img2) | |
print("Images downloaded!") | |
result = DeepFace.verify(img1, img2, model_name=model_name, | |
distance_metric=distance_metric) | |
output["verified"] = result["verified"] | |
output["distance"] = result["distance"] | |
output["similarity"] = (1 - float(result["distance"]))*100 | |
# Delete downloaded images | |
if os.path.isfile(img1): | |
os.remove(img1) | |
os.remove(img2) | |
print("Images are processed and deleted successfully!") | |
return output | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment