Spaces:
Sleeping
Sleeping
Commit
·
8460a2a
1
Parent(s):
9efc67a
added new models and added api docs page
Browse files- app/__init__.py +19 -8
- app/api/routes.py +82 -43
- app/demo/routes.py +27 -10
- app/static/demo/index/script.js +18 -14
- app/static/docs/data.json +38 -0
- app/static/docs/index.css +20 -0
- app/static/docs/index.js +123 -0
- app/static/user/dashboard.js +16 -13
- app/templates/docs/index.html +17 -0
- app/user/routes.py +35 -11
- config.py +16 -13
- face_detection/Models/v1/config.py +2 -0
- face_detection/inference.py +7 -2
- face_recognition/Models/keras_mobilenet_emore_adamw/config.py +3 -0
- face_recognition/Models/keras_mobilenet_emore_adamw/keras_mobilenet_emore_adamw.h5 +3 -0
- face_recognition/Models/keras_mobilenet_emore_adamw/model.h5 +3 -0
- face_recognition/Models/mobilenet_basic_lfw/config.py +3 -0
- face_recognition/Models/mobilenet_basic_lfw/mobilenet_basic_lfw_model.h5 +3 -0
- face_recognition/Models/mobilenet_basic_lfw/model.h5 +3 -0
- face_recognition/aligner.py +1 -1
- face_recognition/inference.py +41 -33
- setup_db.py +17 -17
- test.py +46 -0
app/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask,session
|
| 2 |
from datetime import timedelta
|
| 3 |
|
| 4 |
from face_detection import inference as fd
|
|
@@ -11,14 +11,17 @@ from face_recognition import helper as fr_helper
|
|
| 11 |
|
| 12 |
face_detector=fd.face_detection("face_detection/Models/v1")
|
| 13 |
face_detector.square_preprocessing=fd.square_pad()
|
| 14 |
-
face_recognizer=fr.face_recognition("face_recognition/Models/v1")
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
image_size=544
|
| 18 |
-
p_thres=0.7
|
| 19 |
-
nms_thres=0.3
|
| 20 |
-
batch_size=1
|
| 21 |
-
face_detector.set_mode(p_thres,nms_thres,mode="sized",image_size=image_size,batch_size=batch_size)
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
# def create_app(config_class=Config):
|
|
@@ -51,5 +54,13 @@ def create_app():
|
|
| 51 |
@app.route("/test/")
|
| 52 |
def test_page():
|
| 53 |
return "<h1>This is a test page</h1>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
return app
|
|
|
|
| 1 |
+
from flask import Flask,session,render_template,url_for,json
|
| 2 |
from datetime import timedelta
|
| 3 |
|
| 4 |
from face_detection import inference as fd
|
|
|
|
| 11 |
|
| 12 |
face_detector=fd.face_detection("face_detection/Models/v1")
|
| 13 |
face_detector.square_preprocessing=fd.square_pad()
|
| 14 |
+
# face_recognizer=fr.face_recognition("face_recognition/Models/v1")
|
| 15 |
+
# face_recognizer=fr.face_recognition("face_recognition/Models/mobilenet_basic_lfw")
|
| 16 |
+
face_recognizer=fr.face_recognition("face_recognition/Models/keras_mobilenet_emore_adamw")
|
| 17 |
+
aligner_obj=aligner()
|
| 18 |
|
| 19 |
+
# image_size=544
|
| 20 |
+
# p_thres=0.7
|
| 21 |
+
# nms_thres=0.3
|
| 22 |
+
# batch_size=1
|
| 23 |
+
# face_detector.set_mode(p_thres,nms_thres,mode="sized",image_size=image_size,batch_size=batch_size)
|
| 24 |
+
face_detector.mode="sized"
|
| 25 |
|
| 26 |
|
| 27 |
# def create_app(config_class=Config):
|
|
|
|
| 54 |
@app.route("/test/")
|
| 55 |
def test_page():
|
| 56 |
return "<h1>This is a test page</h1>"
|
| 57 |
+
|
| 58 |
+
@app.route("/api/docs/json/",methods=["GET"])
|
| 59 |
+
def get_docs_json():
|
| 60 |
+
return json.load(open("app/static/docs/data.json","r"))
|
| 61 |
+
|
| 62 |
+
@app.route("/api/docs/")
|
| 63 |
+
def api_docs():
|
| 64 |
+
return render_template("docs/index.html")
|
| 65 |
|
| 66 |
return app
|
app/api/routes.py
CHANGED
|
@@ -6,9 +6,10 @@ import numpy as np
|
|
| 6 |
|
| 7 |
from app import face_detector,face_recognizer,aligner_obj,fd_get_crops,fr_helper
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
def set_image_size(settings,mode):
|
| 14 |
if mode=='small':
|
|
@@ -20,11 +21,22 @@ def set_image_size(settings,mode):
|
|
| 20 |
else:
|
| 21 |
raise("Error")
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
dataBase = access_database_as_admin()
|
| 29 |
cursor=dataBase.cursor()
|
| 30 |
cursor.execute("select * from user_settings where username=%s",[username])
|
|
@@ -43,6 +55,10 @@ def load_settings(username):
|
|
| 43 |
# Disconnecting from the server
|
| 44 |
dataBase.commit()
|
| 45 |
dataBase.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# set face detector settings
|
| 48 |
face_detector.p_thres=settings['p_thres']
|
|
@@ -57,7 +73,7 @@ def load_settings(username):
|
|
| 57 |
|
| 58 |
return settings
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
def is_auth(func):
|
| 63 |
def wrapper_func(*args,**kwargs):
|
|
@@ -78,37 +94,7 @@ def is_auth(func):
|
|
| 78 |
return wrapper_func
|
| 79 |
|
| 80 |
|
| 81 |
-
|
| 82 |
-
@is_auth
|
| 83 |
-
def get_crops(username):
|
| 84 |
-
|
| 85 |
-
settings=load_settings(username)
|
| 86 |
-
set_image_size(settings,settings["db_mode"])
|
| 87 |
-
if "image_size" in request.form: face_detector.image_size=list(map(lambda x:int(x),request.form["image_size"].split(",")))
|
| 88 |
-
if "thres" in request.form: face_recognizer.thres=request.form["thres"]
|
| 89 |
-
print(face_detector.image_size)
|
| 90 |
-
|
| 91 |
-
file = request.files['image']
|
| 92 |
-
|
| 93 |
-
image=Image.open(file.stream).convert("RGB")
|
| 94 |
-
image = ImageOps.exif_transpose(image)
|
| 95 |
-
image=np.array(image)
|
| 96 |
-
print(image.shape)
|
| 97 |
-
|
| 98 |
-
image,objs_found=face_detector.predict(image)
|
| 99 |
-
print(objs_found)
|
| 100 |
-
|
| 101 |
-
all_aligned_crops=fd_get_crops(image,objs_found,aligner_obj,resize=(face_recognizer.model_config.input_size,face_recognizer.model_config.input_size))
|
| 102 |
-
all_aligned_crops_base64=[]
|
| 103 |
-
|
| 104 |
-
for i,aligned_crop in enumerate(all_aligned_crops):
|
| 105 |
-
all_aligned_crops_base64.append(image_to_base64(aligned_crop))
|
| 106 |
-
|
| 107 |
-
return jsonify({"message":"success","crops":all_aligned_crops_base64})
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
@bp.route("/add_person/",methods=["POST"])
|
| 113 |
@is_auth
|
| 114 |
def add_person(username):
|
|
@@ -156,15 +142,60 @@ def remove_person(username):
|
|
| 156 |
return jsonify({"message":"success"})
|
| 157 |
# return jsonify({"message":"success",'image':pred_img})
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
@bp.route("/face_recognize/",methods=["POST"])
|
| 161 |
@is_auth
|
| 162 |
def face_recognition(username):
|
| 163 |
|
| 164 |
-
settings=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
set_image_size(settings,settings["fr_mode"])
|
| 166 |
if "image_size" in request.form: face_detector.image_size=list(map(lambda x:int(x),request.form["image_size"].split(",")))
|
| 167 |
-
if "d_thres" in request.form: face_recognizer.thres=request.form["d_thres"]
|
| 168 |
print(face_detector.image_size)
|
| 169 |
|
| 170 |
# print(request.form)
|
|
@@ -183,16 +214,24 @@ def face_recognition(username):
|
|
| 183 |
for i in range(len(faces)):
|
| 184 |
print(faces[i],":",db_faces_features[i].shape)
|
| 185 |
|
| 186 |
-
|
| 187 |
-
face_recognizer.set_face_db_and_mode(faces=faces,db_faces_features=db_faces_features,distance_mode="best",recognition_mode="repeat")
|
| 188 |
img,objs_found=face_detector.predict(image)
|
| 189 |
h,w=img.shape[:2]
|
| 190 |
tree=fr_helper.objs_found_to_xml("test.jpg",w,h,objs_found)
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
pred_img=fr_helper.show_pred_image(tree,img)
|
| 193 |
pred_img=image_to_base64(pred_img)
|
| 194 |
objs_found=fr_helper.xml_to_objs_found(tree) # everything is okay till here
|
| 195 |
-
# print(objs_found[0])
|
| 196 |
|
| 197 |
objs_found=face_detector.square_preprocessing.rescale(objs_found) #rescale coordinates to original image's resolution
|
| 198 |
# print(objs_found[0])
|
|
|
|
| 6 |
|
| 7 |
from app import face_detector,face_recognizer,aligner_obj,fd_get_crops,fr_helper
|
| 8 |
|
| 9 |
+
from config import demo_config
|
| 10 |
|
| 11 |
|
| 12 |
+
##################################################################settings#######################################################################
|
| 13 |
|
| 14 |
def set_image_size(settings,mode):
|
| 15 |
if mode=='small':
|
|
|
|
| 21 |
else:
|
| 22 |
raise("Error")
|
| 23 |
|
| 24 |
+
def get_default_settings():
|
| 25 |
+
settings_dict={}
|
| 26 |
+
#p_thres,nms_thres,small_size,large_size,d_thres,a_thres,db_mode,fr_mode
|
| 27 |
+
|
| 28 |
+
#p_thres,nms_thres
|
| 29 |
+
settings_dict['p_thres']=face_detector.model_config.p_thres
|
| 30 |
+
settings_dict['nms_thres']=face_detector.model_config.nms_thres
|
| 31 |
+
# d_thres
|
| 32 |
+
settings_dict['d_thres']=face_recognizer.model_config.d_thres
|
| 33 |
+
|
| 34 |
+
#small_size,large_size,a_thres,db_mode,fr_mode
|
| 35 |
+
settings_dict.update(demo_config)
|
| 36 |
|
| 37 |
+
return settings_dict
|
| 38 |
+
|
| 39 |
+
def get_settings(username):
|
| 40 |
dataBase = access_database_as_admin()
|
| 41 |
cursor=dataBase.cursor()
|
| 42 |
cursor.execute("select * from user_settings where username=%s",[username])
|
|
|
|
| 55 |
# Disconnecting from the server
|
| 56 |
dataBase.commit()
|
| 57 |
dataBase.close()
|
| 58 |
+
return settings
|
| 59 |
+
|
| 60 |
+
def load_settings(settings):
|
| 61 |
+
|
| 62 |
|
| 63 |
# set face detector settings
|
| 64 |
face_detector.p_thres=settings['p_thres']
|
|
|
|
| 73 |
|
| 74 |
return settings
|
| 75 |
|
| 76 |
+
############################################################settings_end#########################################################################
|
| 77 |
|
| 78 |
def is_auth(func):
|
| 79 |
def wrapper_func(*args,**kwargs):
|
|
|
|
| 94 |
return wrapper_func
|
| 95 |
|
| 96 |
|
| 97 |
+
#################################################################change_db############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
@bp.route("/add_person/",methods=["POST"])
|
| 99 |
@is_auth
|
| 100 |
def add_person(username):
|
|
|
|
| 142 |
return jsonify({"message":"success"})
|
| 143 |
# return jsonify({"message":"success",'image':pred_img})
|
| 144 |
|
| 145 |
+
#################################################################change_db_end############################################################################
|
| 146 |
+
|
| 147 |
+
@bp.route("/get_crops/",methods=["POST"])
|
| 148 |
+
@is_auth
|
| 149 |
+
def get_crops(username):
|
| 150 |
+
|
| 151 |
+
settings=get_settings(username)
|
| 152 |
+
|
| 153 |
+
for setting in settings.keys():
|
| 154 |
+
if setting in request.form:
|
| 155 |
+
settings[setting]=request.form[setting]
|
| 156 |
+
|
| 157 |
+
load_settings(settings)
|
| 158 |
+
|
| 159 |
+
set_image_size(settings,settings["db_mode"])
|
| 160 |
+
if "image_size" in request.form: face_detector.image_size=list(map(lambda x:int(x),request.form["image_size"].split(",")))
|
| 161 |
+
print(face_detector.image_size)
|
| 162 |
+
|
| 163 |
+
file = request.files['image']
|
| 164 |
+
|
| 165 |
+
image=Image.open(file.stream).convert("RGB")
|
| 166 |
+
image = ImageOps.exif_transpose(image)
|
| 167 |
+
image=np.array(image)
|
| 168 |
+
print(image.shape)
|
| 169 |
+
|
| 170 |
+
image,objs_found=face_detector.predict(image)
|
| 171 |
+
print(objs_found)
|
| 172 |
+
|
| 173 |
+
all_aligned_crops=fd_get_crops(image,objs_found,aligner_obj,resize=(face_recognizer.model_config.input_size,face_recognizer.model_config.input_size))
|
| 174 |
+
all_aligned_crops_base64=[]
|
| 175 |
+
|
| 176 |
+
for i,aligned_crop in enumerate(all_aligned_crops):
|
| 177 |
+
all_aligned_crops_base64.append(image_to_base64(aligned_crop))
|
| 178 |
+
|
| 179 |
+
return jsonify({"message":"success","crops":all_aligned_crops_base64})
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
|
| 186 |
@bp.route("/face_recognize/",methods=["POST"])
|
| 187 |
@is_auth
|
| 188 |
def face_recognition(username):
|
| 189 |
|
| 190 |
+
settings=get_settings(username)
|
| 191 |
+
|
| 192 |
+
for setting in settings.keys():
|
| 193 |
+
if setting in request.form:
|
| 194 |
+
settings[setting]=request.form[setting]
|
| 195 |
+
|
| 196 |
+
load_settings(settings)
|
| 197 |
set_image_size(settings,settings["fr_mode"])
|
| 198 |
if "image_size" in request.form: face_detector.image_size=list(map(lambda x:int(x),request.form["image_size"].split(",")))
|
|
|
|
| 199 |
print(face_detector.image_size)
|
| 200 |
|
| 201 |
# print(request.form)
|
|
|
|
| 214 |
for i in range(len(faces)):
|
| 215 |
print(faces[i],":",db_faces_features[i].shape)
|
| 216 |
|
| 217 |
+
|
|
|
|
| 218 |
img,objs_found=face_detector.predict(image)
|
| 219 |
h,w=img.shape[:2]
|
| 220 |
tree=fr_helper.objs_found_to_xml("test.jpg",w,h,objs_found)
|
| 221 |
+
|
| 222 |
+
# face_recognizer.set_face_db_and_mode(faces=faces,db_faces_features=db_faces_features,distance_mode="avg",recognition_mode="repeat")
|
| 223 |
+
face_recognizer.set_face_db_and_mode(faces=faces,db_faces_features=db_faces_features,distance_mode="best",recognition_mode="repeat")
|
| 224 |
+
|
| 225 |
+
if len(faces)>0:
|
| 226 |
+
tree=face_recognizer.predict(img,tree)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# print(objs_found[0])
|
| 230 |
+
|
| 231 |
+
|
| 232 |
pred_img=fr_helper.show_pred_image(tree,img)
|
| 233 |
pred_img=image_to_base64(pred_img)
|
| 234 |
objs_found=fr_helper.xml_to_objs_found(tree) # everything is okay till here
|
|
|
|
| 235 |
|
| 236 |
objs_found=face_detector.square_preprocessing.rescale(objs_found) #rescale coordinates to original image's resolution
|
| 237 |
# print(objs_found[0])
|
app/demo/routes.py
CHANGED
|
@@ -11,9 +11,10 @@ import uuid
|
|
| 11 |
from flask import render_template,request,send_from_directory,session,jsonify,json
|
| 12 |
from app import helper
|
| 13 |
from PIL import ImageOps
|
| 14 |
-
from app.helper import generate_random_id,
|
| 15 |
from app.demo import bp
|
| 16 |
import copy
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
|
|
@@ -166,27 +167,43 @@ def face_recognition():
|
|
| 166 |
return jsonify({"message":"success",'image':pred_img})
|
| 167 |
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
@bp.route("/get_settings/",methods=['GET'])
|
| 170 |
def get_settings():
|
| 171 |
session.permanent=True
|
| 172 |
if "demo" not in session:
|
| 173 |
-
|
| 174 |
-
cursor=dataBase.cursor()
|
| 175 |
-
cursor.execute("select * from default_settings where page='demo'")
|
| 176 |
-
|
| 177 |
session["demo"]={'settings':dict()}
|
| 178 |
-
session["demo"]['settings']=
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
| 182 |
|
| 183 |
return session["demo"]['settings']
|
| 184 |
|
| 185 |
@bp.route("/reset_settings/",methods=['GET'])
|
| 186 |
def reset_settings():
|
| 187 |
del session["demo"]
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
return {"message":"success"}
|
| 190 |
|
| 191 |
@bp.route("/update_settings/",methods=['POST'])
|
| 192 |
def update_settings():
|
|
|
|
| 11 |
from flask import render_template,request,send_from_directory,session,jsonify,json
|
| 12 |
from app import helper
|
| 13 |
from PIL import ImageOps
|
| 14 |
+
from app.helper import generate_random_id,image_to_base64,base64_to_image
|
| 15 |
from app.demo import bp
|
| 16 |
import copy
|
| 17 |
+
from config import demo_config
|
| 18 |
|
| 19 |
|
| 20 |
|
|
|
|
| 167 |
return jsonify({"message":"success",'image':pred_img})
|
| 168 |
|
| 169 |
|
| 170 |
+
def get_default_settings():
|
| 171 |
+
settings_dict={}
|
| 172 |
+
#p_thres,nms_thres,small_size,large_size,d_thres,a_thres,db_mode,fr_mode
|
| 173 |
+
|
| 174 |
+
#p_thres,nms_thres
|
| 175 |
+
settings_dict['p_thres']=face_detector.model_config.p_thres
|
| 176 |
+
settings_dict['nms_thres']=face_detector.model_config.nms_thres
|
| 177 |
+
# d_thres
|
| 178 |
+
settings_dict['d_thres']=face_recognizer.model_config.d_thres
|
| 179 |
+
|
| 180 |
+
#small_size,large_size,a_thres,db_mode,fr_mode
|
| 181 |
+
settings_dict.update(demo_config)
|
| 182 |
+
|
| 183 |
+
return settings_dict
|
| 184 |
+
|
| 185 |
@bp.route("/get_settings/",methods=['GET'])
|
| 186 |
def get_settings():
|
| 187 |
session.permanent=True
|
| 188 |
if "demo" not in session:
|
| 189 |
+
|
|
|
|
|
|
|
|
|
|
| 190 |
session["demo"]={'settings':dict()}
|
| 191 |
+
session["demo"]['settings']=get_default_settings()
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
|
| 197 |
|
| 198 |
return session["demo"]['settings']
|
| 199 |
|
| 200 |
@bp.route("/reset_settings/",methods=['GET'])
|
| 201 |
def reset_settings():
|
| 202 |
del session["demo"]
|
| 203 |
+
session["demo"]={'settings':dict()}
|
| 204 |
+
session["demo"]['settings']=get_default_settings()
|
| 205 |
|
| 206 |
+
return {"message":"success",**session["demo"]['settings']}
|
| 207 |
|
| 208 |
@bp.route("/update_settings/",methods=['POST'])
|
| 209 |
def update_settings():
|
app/static/demo/index/script.js
CHANGED
|
@@ -432,6 +432,22 @@ function hide_settings(){
|
|
| 432 |
}
|
| 433 |
|
| 434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
function get_settings(){
|
| 437 |
fetch("get_settings/",{
|
|
@@ -440,19 +456,7 @@ function get_settings(){
|
|
| 440 |
return response.json();
|
| 441 |
}).then(function(res){
|
| 442 |
console.log(res);
|
| 443 |
-
|
| 444 |
-
p_thres.value=p_thresValue.innerText=res['p_thres'];
|
| 445 |
-
nms_thres.value=nms_thresValue.innerText=res['nms_thres'];
|
| 446 |
-
|
| 447 |
-
small_size.value=small_sizeValue.innerText=res['small_size'];
|
| 448 |
-
large_size.value=large_sizeValue.innerText=res['large_size'];
|
| 449 |
-
|
| 450 |
-
d_thres.value=d_thresValue.innerText=res['d_thres'];
|
| 451 |
-
a_thres.value=a_thresValue.innerText=res['a_thres'];
|
| 452 |
-
|
| 453 |
-
db_mode.value=res['db_mode'];
|
| 454 |
-
fr_mode.value=res['fr_mode'];
|
| 455 |
-
console.log(res['db_mode'],res['fr_mode']);
|
| 456 |
})
|
| 457 |
}
|
| 458 |
get_settings();
|
|
@@ -492,7 +496,7 @@ function reset_settings(){
|
|
| 492 |
}).then(function(res){
|
| 493 |
console.log(res);
|
| 494 |
if(res['message']=='success')
|
| 495 |
-
|
| 496 |
}
|
| 497 |
);
|
| 498 |
}
|
|
|
|
| 432 |
}
|
| 433 |
|
| 434 |
|
| 435 |
+
function update_settings_html(res){
|
| 436 |
+
p_thres.value=p_thresValue.innerText=res['p_thres'];
|
| 437 |
+
nms_thres.value=nms_thresValue.innerText=res['nms_thres'];
|
| 438 |
+
|
| 439 |
+
small_size.value=small_sizeValue.innerText=res['small_size'];
|
| 440 |
+
large_size.value=large_sizeValue.innerText=res['large_size'];
|
| 441 |
+
|
| 442 |
+
d_thres.value=d_thresValue.innerText=res['d_thres'];
|
| 443 |
+
a_thres.value=a_thresValue.innerText=res['a_thres'];
|
| 444 |
+
|
| 445 |
+
db_mode.value=res['db_mode'];
|
| 446 |
+
fr_mode.value=res['fr_mode'];
|
| 447 |
+
// console.log(res['db_mode'],res['fr_mode']);
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
|
| 451 |
|
| 452 |
function get_settings(){
|
| 453 |
fetch("get_settings/",{
|
|
|
|
| 456 |
return response.json();
|
| 457 |
}).then(function(res){
|
| 458 |
console.log(res);
|
| 459 |
+
update_settings_html(res);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
})
|
| 461 |
}
|
| 462 |
get_settings();
|
|
|
|
| 496 |
}).then(function(res){
|
| 497 |
console.log(res);
|
| 498 |
if(res['message']=='success')
|
| 499 |
+
update_settings_html(res);
|
| 500 |
}
|
| 501 |
);
|
| 502 |
}
|
app/static/docs/data.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"color":"#df7fff",
|
| 4 |
+
"route_name":"get_crops",
|
| 5 |
+
"route":"/api/get_crops",
|
| 6 |
+
"method":"POST",
|
| 7 |
+
"summary":"This route is used to get face crops from any image",
|
| 8 |
+
"request_params":[
|
| 9 |
+
{"name":"image","summary":"Image to get face crops from.","type":"File","required":"*"},
|
| 10 |
+
{"name":"access_key","summary":"access key related with your account.","type":"json","required":"*"},
|
| 11 |
+
{"name":"settings-parameter","summary":"pass any settings for example \"d_thres\":0.3 .","type":"json","required":""}
|
| 12 |
+
],
|
| 13 |
+
"response_params":[
|
| 14 |
+
{"name":"message","summary":"\"success\" if everything is fine.","type":"Text"},
|
| 15 |
+
{"name":"crops","summary":"return list of crop images.","type":"list of base64 values"}
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
|
| 19 |
+
{
|
| 20 |
+
"color":"#acff7f",
|
| 21 |
+
"route_name":"face_recognize",
|
| 22 |
+
"route":"/api/face_recognize",
|
| 23 |
+
"method":"POST",
|
| 24 |
+
"summary":"This route is used to do face recognition based on the images in the db.",
|
| 25 |
+
"request_params":[
|
| 26 |
+
{"name":"image","summary":"Image to get face crops from.","type":"File","required":"*"},
|
| 27 |
+
{"name":"access_key","summary":"access key related with your account.","type":"json","required":"*"},
|
| 28 |
+
{"name":"settings-parameter","summary":"pass any settings for example \"d_thres\":0.3 .","type":"json","required":""}
|
| 29 |
+
],
|
| 30 |
+
"response_params":[
|
| 31 |
+
{"name":"message","summary":"\"success\" if everything is fine.","type":"Text"},
|
| 32 |
+
{"name":"pred_image","summary":"image with prediction boxes","type":"base64"},
|
| 33 |
+
{"name":"person_ids","summary":"list of person_id(\"face\" if face is not found)","type":"list of string"},
|
| 34 |
+
{"name":"crops","summary":"return list of crop images.","type":"list of base64 values"},
|
| 35 |
+
{"name":"objs_found","summary":"dictionary of faces found with coordinates and names .","type":"dictionary"}
|
| 36 |
+
]
|
| 37 |
+
}
|
| 38 |
+
]
|
app/static/docs/index.css
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*{
|
| 2 |
+
/* font-weight: bold; */
|
| 3 |
+
font-family: 'Poppins';
|
| 4 |
+
}
|
| 5 |
+
.container{
|
| 6 |
+
display:flex;
|
| 7 |
+
flex-direction: column;
|
| 8 |
+
align-items: center;
|
| 9 |
+
}
|
| 10 |
+
.endpoint{
|
| 11 |
+
/* height: 200px; */
|
| 12 |
+
/* background-color: aquamarine; */
|
| 13 |
+
background-color: aquamarine;
|
| 14 |
+
margin-top:50px;
|
| 15 |
+
width:80%;
|
| 16 |
+
padding:0px 10px;
|
| 17 |
+
border-radius: 20px;
|
| 18 |
+
|
| 19 |
+
box-shadow: black 1px 2px 21px -10px;
|
| 20 |
+
}
|
app/static/docs/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var base_url=window.location.href.split("/").slice(0,3).join("/");
|
| 2 |
+
// console.log(base_url);
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
var data={
|
| 6 |
+
"route_name":"get_crops",
|
| 7 |
+
"route":"/api/get_crops",
|
| 8 |
+
"method":"POST",
|
| 9 |
+
"summary":"This route is used to get face crops from any image",
|
| 10 |
+
"request_params":[
|
| 11 |
+
{"name":"image","summary":"Image to get face crops from.","type":"File","required":"*"},
|
| 12 |
+
{"name":"access_key","summary":"access key related with your account.","type":"json","required":"*"},
|
| 13 |
+
{"name":"settings-parameter","summary":"pass any settings for example \"d_thres\":0.3 .","type":"json","required":""},
|
| 14 |
+
],
|
| 15 |
+
"response_params":[
|
| 16 |
+
{"name":"message","summary":"\"success\" if everything is fine.","type":"Text"},
|
| 17 |
+
{"name":"crops","summary":"return list of crop images.","type":"list of base64 values"},
|
| 18 |
+
],
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
function add_endpoint(data){
|
| 24 |
+
// <div class="endpoint">
|
| 25 |
+
// <h3 class="route_name">get_crops</h3>
|
| 26 |
+
// <h4>Method:<span class="method_type">POST</span></h4>
|
| 27 |
+
// <p class="summary">This route is used to get face crops from any image</p>
|
| 28 |
+
// <p><b>route:	</b><span class="api_route">/api/get_crops</span></p>
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
// <b>Request Parameters:</b>
|
| 32 |
+
// <ul>
|
| 33 |
+
// <li>
|
| 34 |
+
// <span><span class="param_name">image<span>:	</span>
|
| 35 |
+
// <span class="param_summary">Image to get face crops from.</span>
|
| 36 |
+
// <span>(Type:	<span class="param_type">File</span>)</span>
|
| 37 |
+
// </li>
|
| 38 |
+
// <li>
|
| 39 |
+
// <span><span class="param_name">settings-parameter<span>:	</span>
|
| 40 |
+
// <span class="param_summary">pass any settings for example "d_thres":0.3 .</span>
|
| 41 |
+
// <span>(Type:	<span class="param_type">json</span>)</span>
|
| 42 |
+
// </li>
|
| 43 |
+
// <li>
|
| 44 |
+
// <span><span class="param_name">access_key<span>:	</span>
|
| 45 |
+
// <span class="param_summary">access key related with your account.</span>
|
| 46 |
+
// <span>(Type:	<span class="param_type">json</span>)</span>
|
| 47 |
+
// </li>
|
| 48 |
+
|
| 49 |
+
// </ul>
|
| 50 |
+
// <b>Response Body:</b>
|
| 51 |
+
// <ul>
|
| 52 |
+
// <li>
|
| 53 |
+
|
| 54 |
+
// <span><span class="param_name">message<span>:	</span>
|
| 55 |
+
// <span class="param_summary">"success" if everything is fine.</span>
|
| 56 |
+
// <span>(Type:	<span class="param_type">Text</span>)</span>
|
| 57 |
+
// </li>
|
| 58 |
+
// <li>
|
| 59 |
+
|
| 60 |
+
// <span><span class="param_name">crops<span>:	</span>
|
| 61 |
+
// <span class="param_summary">return list of crop images.</span>
|
| 62 |
+
// <span>(Type:	<span class="param_type">list of base64 values</span>)</span>
|
| 63 |
+
// </li>
|
| 64 |
+
|
| 65 |
+
// </ul>
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
// </div>
|
| 69 |
+
var parent_div=document.querySelector(".container");
|
| 70 |
+
var endpoint=document.createElement("div");
|
| 71 |
+
endpoint.className="endpoint";
|
| 72 |
+
// console.log(("color" in data));
|
| 73 |
+
if ("color" in data) {
|
| 74 |
+
endpoint.style.backgroundColor=data["color"];
|
| 75 |
+
}
|
| 76 |
+
parent_div.appendChild(endpoint);
|
| 77 |
+
|
| 78 |
+
endpoint.innerHTML+=`<h3 class="route_name">${data['route_name']}</h3> `;
|
| 79 |
+
endpoint.innerHTML+=`<h4>Method:	<span class="method_type">${data['method']}</span></h4>`;
|
| 80 |
+
endpoint.innerHTML+=`<p class="summary">${data['summary']}</p>`;
|
| 81 |
+
endpoint.innerHTML+=`<p><b>route:	</b><span class="api_route">${base_url+data["route"]}</span></p>`;
|
| 82 |
+
endpoint.innerHTML+=`<b>Request Parameters:</b>`;
|
| 83 |
+
|
| 84 |
+
var params=document.createElement("ul");
|
| 85 |
+
endpoint.appendChild(params);
|
| 86 |
+
|
| 87 |
+
data['request_params'].map(param=>{
|
| 88 |
+
// request parameters
|
| 89 |
+
|
| 90 |
+
var list=document.createElement("li");
|
| 91 |
+
list.innerHTML+=`<span><span class="param_name">${param["name"]}<span>:	</span>`;
|
| 92 |
+
list.innerHTML+=`<span class="param_summary">${param['summary']}</span>`;
|
| 93 |
+
list.innerHTML+=`<span>(Type:	<span class="param_type">${param['type']}</span>)${param['required']}</span>`;
|
| 94 |
+
params.appendChild(list);
|
| 95 |
+
|
| 96 |
+
})
|
| 97 |
+
endpoint.innerHTML+=`<b>Response Body:</b>`;
|
| 98 |
+
var params=document.createElement("ul");
|
| 99 |
+
endpoint.appendChild(params);
|
| 100 |
+
data['response_params'].map(param=>{
|
| 101 |
+
// response parameters
|
| 102 |
+
|
| 103 |
+
var list=document.createElement("li");
|
| 104 |
+
list.innerHTML+=`<span><span class="param_name">${param['name']}<span>:	</span>`;
|
| 105 |
+
list.innerHTML+=`<span class="param_summary">${param["summary"]}</span>`;
|
| 106 |
+
list.innerHTML+=`<span>(Type:	<span class="param_type">${param["type"]}</span>)</span>`;
|
| 107 |
+
params.appendChild(list);
|
| 108 |
+
|
| 109 |
+
})
|
| 110 |
+
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
fetch("json/").then(res=>{return res.json();}).then(res=>{
|
| 117 |
+
res.map(data=>{
|
| 118 |
+
add_endpoint(data);
|
| 119 |
+
})
|
| 120 |
+
})
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
|
app/static/user/dashboard.js
CHANGED
|
@@ -416,6 +416,20 @@ function hide_settings(){
|
|
| 416 |
document.querySelector('#container').classList.remove("blur");
|
| 417 |
}
|
| 418 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
|
| 421 |
function get_settings(){
|
|
@@ -425,19 +439,8 @@ function get_settings(){
|
|
| 425 |
return response.json();
|
| 426 |
}).then(function(res){
|
| 427 |
console.log(res);
|
| 428 |
-
|
| 429 |
-
p_thres.value=p_thresValue.innerText=res['p_thres'];
|
| 430 |
-
nms_thres.value=nms_thresValue.innerText=res['nms_thres'];
|
| 431 |
|
| 432 |
-
small_size.value=small_sizeValue.innerText=res['small_size'];
|
| 433 |
-
large_size.value=large_sizeValue.innerText=res['large_size'];
|
| 434 |
-
|
| 435 |
-
d_thres.value=d_thresValue.innerText=res['d_thres'];
|
| 436 |
-
a_thres.value=a_thresValue.innerText=res['a_thres'];
|
| 437 |
-
|
| 438 |
-
db_mode.value=res['db_mode'];
|
| 439 |
-
fr_mode.value=res['fr_mode'];
|
| 440 |
-
console.log(res['db_mode'],res['fr_mode']);
|
| 441 |
})
|
| 442 |
}
|
| 443 |
get_settings();
|
|
@@ -477,7 +480,7 @@ function reset_settings(){
|
|
| 477 |
}).then(function(res){
|
| 478 |
console.log(res);
|
| 479 |
if(res['message']=='success')
|
| 480 |
-
|
| 481 |
}
|
| 482 |
);
|
| 483 |
}
|
|
|
|
| 416 |
document.querySelector('#container').classList.remove("blur");
|
| 417 |
}
|
| 418 |
|
| 419 |
+
function update_settings_html(res){
|
| 420 |
+
p_thres.value=p_thresValue.innerText=res['p_thres'];
|
| 421 |
+
nms_thres.value=nms_thresValue.innerText=res['nms_thres'];
|
| 422 |
+
|
| 423 |
+
small_size.value=small_sizeValue.innerText=res['small_size'];
|
| 424 |
+
large_size.value=large_sizeValue.innerText=res['large_size'];
|
| 425 |
+
|
| 426 |
+
d_thres.value=d_thresValue.innerText=res['d_thres'];
|
| 427 |
+
a_thres.value=a_thresValue.innerText=res['a_thres'];
|
| 428 |
+
|
| 429 |
+
db_mode.value=res['db_mode'];
|
| 430 |
+
fr_mode.value=res['fr_mode'];
|
| 431 |
+
// console.log(res['db_mode'],res['fr_mode']);
|
| 432 |
+
}
|
| 433 |
|
| 434 |
|
| 435 |
function get_settings(){
|
|
|
|
| 439 |
return response.json();
|
| 440 |
}).then(function(res){
|
| 441 |
console.log(res);
|
| 442 |
+
update_settings_html(res);
|
|
|
|
|
|
|
| 443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
})
|
| 445 |
}
|
| 446 |
get_settings();
|
|
|
|
| 480 |
}).then(function(res){
|
| 481 |
console.log(res);
|
| 482 |
if(res['message']=='success')
|
| 483 |
+
update_settings_html(res);
|
| 484 |
}
|
| 485 |
);
|
| 486 |
}
|
app/templates/docs/index.html
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends 'base.html' %}
|
| 2 |
+
{% block title %}api documentations{% endblock %}
|
| 3 |
+
{% block css %}
|
| 4 |
+
<link type="text/css" rel="stylesheet" href="{{ url_for('static',filename='docs/index.css') }}">
|
| 5 |
+
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"> -->
|
| 6 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
|
| 7 |
+
{% endblock %}
|
| 8 |
+
{% block body %}
|
| 9 |
+
<h1>API documentations</h1>
|
| 10 |
+
|
| 11 |
+
<div class="container">
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
</div>
|
| 15 |
+
<script src="{{ url_for('static',filename='docs/index.js') }}"></script>
|
| 16 |
+
|
| 17 |
+
{% endblock %}
|
app/user/routes.py
CHANGED
|
@@ -10,6 +10,7 @@ from PIL import Image
|
|
| 10 |
import os
|
| 11 |
import numpy as np
|
| 12 |
from app import face_detector,face_recognizer,aligner_obj,fd_get_crops,fr_helper,fd,fr
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
|
|
@@ -213,6 +214,22 @@ def get_image_size(mode):
|
|
| 213 |
|
| 214 |
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
@bp.route("/get_settings/",methods=['GET'])
|
| 217 |
def get_settings():
|
| 218 |
global settings
|
|
@@ -225,13 +242,15 @@ def get_settings():
|
|
| 225 |
|
| 226 |
if settings is None:
|
| 227 |
# get default settings and insert a row in user_settings
|
| 228 |
-
|
| 229 |
-
settings=
|
| 230 |
-
columns=
|
| 231 |
-
|
|
|
|
| 232 |
|
|
|
|
|
|
|
| 233 |
|
| 234 |
-
settings= dict(zip(columns, settings))
|
| 235 |
# Disconnecting from the server
|
| 236 |
dataBase.commit()
|
| 237 |
dataBase.close()
|
|
@@ -240,24 +259,29 @@ def get_settings():
|
|
| 240 |
|
| 241 |
return settings
|
| 242 |
|
|
|
|
| 243 |
@bp.route("/reset_settings/",methods=['GET'])
|
| 244 |
def reset_settings():
|
|
|
|
|
|
|
| 245 |
dataBase = access_database_as_admin()
|
| 246 |
cursor=dataBase.cursor()
|
| 247 |
|
| 248 |
-
|
| 249 |
-
settings=
|
| 250 |
-
columns=
|
|
|
|
|
|
|
| 251 |
print(settings)
|
| 252 |
-
cursor.execute(f"update user_settings set {','.join(list(map(lambda x:x+'=%s',columns)))} where username=%s;",settings+
|
| 253 |
|
| 254 |
# Disconnecting from the server
|
| 255 |
dataBase.commit()
|
| 256 |
dataBase.close()
|
| 257 |
|
| 258 |
-
|
| 259 |
|
| 260 |
-
return {"message":"success"}
|
| 261 |
|
| 262 |
@bp.route("/update_settings/",methods=['POST'])
|
| 263 |
def update_settings():
|
|
|
|
| 10 |
import os
|
| 11 |
import numpy as np
|
| 12 |
from app import face_detector,face_recognizer,aligner_obj,fd_get_crops,fr_helper,fd,fr
|
| 13 |
+
from config import user_config
|
| 14 |
|
| 15 |
|
| 16 |
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
+
def get_default_settings():
|
| 218 |
+
settings_dict={}
|
| 219 |
+
#p_thres,nms_thres,small_size,large_size,d_thres,a_thres,db_mode,fr_mode
|
| 220 |
+
|
| 221 |
+
#p_thres,nms_thres
|
| 222 |
+
settings_dict['p_thres']=face_detector.model_config.p_thres
|
| 223 |
+
settings_dict['nms_thres']=face_detector.model_config.nms_thres
|
| 224 |
+
# d_thres
|
| 225 |
+
settings_dict['d_thres']=face_recognizer.model_config.d_thres
|
| 226 |
+
|
| 227 |
+
#small_size,large_size,a_thres,db_mode,fr_mode
|
| 228 |
+
settings_dict.update(user_config)
|
| 229 |
+
|
| 230 |
+
return settings_dict
|
| 231 |
+
|
| 232 |
+
|
| 233 |
@bp.route("/get_settings/",methods=['GET'])
|
| 234 |
def get_settings():
|
| 235 |
global settings
|
|
|
|
| 242 |
|
| 243 |
if settings is None:
|
| 244 |
# get default settings and insert a row in user_settings
|
| 245 |
+
|
| 246 |
+
settings=get_default_settings()
|
| 247 |
+
columns=["p_thres","nms_thres","small_size","large_size","d_thres","a_thres","db_mode","fr_mode"]
|
| 248 |
+
|
| 249 |
+
cursor.execute(f"insert into user_settings(username,{','.join(columns)}) values(%s,{','.join(map(lambda x:'%s',columns))})",[session['user']['username']]+[settings[col] for col in columns])
|
| 250 |
|
| 251 |
+
else:
|
| 252 |
+
settings= dict(zip(columns, settings))
|
| 253 |
|
|
|
|
| 254 |
# Disconnecting from the server
|
| 255 |
dataBase.commit()
|
| 256 |
dataBase.close()
|
|
|
|
| 259 |
|
| 260 |
return settings
|
| 261 |
|
| 262 |
+
|
| 263 |
@bp.route("/reset_settings/",methods=['GET'])
|
| 264 |
def reset_settings():
|
| 265 |
+
global settings
|
| 266 |
+
|
| 267 |
dataBase = access_database_as_admin()
|
| 268 |
cursor=dataBase.cursor()
|
| 269 |
|
| 270 |
+
|
| 271 |
+
settings=get_default_settings()
|
| 272 |
+
columns=["p_thres","nms_thres","small_size","large_size","d_thres","a_thres","db_mode","fr_mode"]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
print(settings)
|
| 276 |
+
cursor.execute(f"update user_settings set {','.join(list(map(lambda x:x+'=%s',columns)))} where username=%s;",[settings[col] for col in columns]+[session['user']['username']])
|
| 277 |
|
| 278 |
# Disconnecting from the server
|
| 279 |
dataBase.commit()
|
| 280 |
dataBase.close()
|
| 281 |
|
| 282 |
+
|
| 283 |
|
| 284 |
+
return {"message":"success",**settings}
|
| 285 |
|
| 286 |
@bp.route("/update_settings/",methods=['POST'])
|
| 287 |
def update_settings():
|
config.py
CHANGED
|
@@ -1,17 +1,20 @@
|
|
| 1 |
-
import os
|
| 2 |
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# class Config:
|
| 17 |
-
# SECRET_KEY=os.environ.get("SECRET_KEY")
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
demo_config={
|
| 3 |
|
| 4 |
+
"small_size":256,
|
| 5 |
+
"large_size":1024,
|
| 6 |
+
|
| 7 |
+
"db_mode":'small', # 'small','large','both'
|
| 8 |
+
"fr_mode":'large', # 'small','large','both'
|
| 9 |
|
| 10 |
+
"a_thres":0.6
|
| 11 |
+
}
|
| 12 |
+
user_config={
|
| 13 |
+
"small_size":544,
|
| 14 |
+
"large_size":2080,
|
| 15 |
+
|
| 16 |
+
"db_mode":'small', # 'small','large','both'
|
| 17 |
+
"fr_mode":'both', # 'small','large','both'
|
| 18 |
|
| 19 |
+
"a_thres":0.6
|
| 20 |
+
}
|
|
|
|
|
|
|
|
|
face_detection/Models/v1/config.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
p_thres=0.5
|
| 2 |
+
nms_thres=0.3
|
face_detection/inference.py
CHANGED
|
@@ -3,6 +3,7 @@ import numpy as np
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import math
|
| 5 |
import copy
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
|
|
@@ -96,7 +97,11 @@ class face_detection:
|
|
| 96 |
self.modes_available=["tiled","sized"]
|
| 97 |
self.square_preprocessing=square_crop
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
all_objs_found=[]
|
| 101 |
|
| 102 |
for i in range(math.ceil(img.shape[0]/batch_size)):
|
|
@@ -151,7 +156,7 @@ class face_detection:
|
|
| 151 |
return all_objs_found_joined
|
| 152 |
|
| 153 |
|
| 154 |
-
def set_mode(self,p_thres,nms_thres,batch_size=
|
| 155 |
# mode : tiled or sized
|
| 156 |
|
| 157 |
self.p_thres=p_thres
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import math
|
| 5 |
import copy
|
| 6 |
+
import importlib
|
| 7 |
|
| 8 |
|
| 9 |
|
|
|
|
| 97 |
self.modes_available=["tiled","sized"]
|
| 98 |
self.square_preprocessing=square_crop
|
| 99 |
|
| 100 |
+
config_file_path='.'.join(model_path.split("/"))+".config"
|
| 101 |
+
# print(config_file_path)
|
| 102 |
+
self.model_config= importlib.import_module(config_file_path)
|
| 103 |
+
|
| 104 |
+
def invoke_model(self,img,p,iou_threshold,batch_size):
|
| 105 |
all_objs_found=[]
|
| 106 |
|
| 107 |
for i in range(math.ceil(img.shape[0]/batch_size)):
|
|
|
|
| 156 |
return all_objs_found_joined
|
| 157 |
|
| 158 |
|
| 159 |
+
def set_mode(self,p_thres,nms_thres,batch_size=1,mode="sized",**kwargs):
|
| 160 |
# mode : tiled or sized
|
| 161 |
|
| 162 |
self.p_thres=p_thres
|
face_recognition/Models/keras_mobilenet_emore_adamw/config.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
input_size=112
|
| 2 |
+
d_thres=0.2830035090446472
|
| 3 |
+
large_distance=-1
|
face_recognition/Models/keras_mobilenet_emore_adamw/keras_mobilenet_emore_adamw.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c5cec8f368a176dab4ccf48be1cd25aa7a4bb2ced049a38c86922f8bb5c70ac
|
| 3 |
+
size 14285304
|
face_recognition/Models/keras_mobilenet_emore_adamw/model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4d1d7a8631e59c14f774391e52187d07e20643b53058377276c89908c982516f
|
| 3 |
+
size 14191896
|
face_recognition/Models/mobilenet_basic_lfw/config.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
input_size=112
|
| 2 |
+
d_thres=0.2830035090446472
|
| 3 |
+
large_distance=-1
|
face_recognition/Models/mobilenet_basic_lfw/mobilenet_basic_lfw_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:886d91bf3bb317399f07222ff014bca71495fbd9ea35cd9722dfdb9987b4b851
|
| 3 |
+
size 14290152
|
face_recognition/Models/mobilenet_basic_lfw/model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ce5b5fc2eca86cba3fc09cdcd52aa77e2064dd40ffce3b18f7f81d255ba6f516
|
| 3 |
+
size 14192120
|
face_recognition/aligner.py
CHANGED
|
@@ -10,7 +10,7 @@ import shutil
|
|
| 10 |
|
| 11 |
|
| 12 |
class aligner:
|
| 13 |
-
def __init__(self,min_aligner_confidence):
|
| 14 |
mp_face_mesh = mp.solutions.face_mesh
|
| 15 |
|
| 16 |
self.face_mesh_images = mp_face_mesh.FaceMesh(static_image_mode=True, max_num_faces=1,
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
class aligner:
|
| 13 |
+
def __init__(self,min_aligner_confidence=0.5):
|
| 14 |
mp_face_mesh = mp.solutions.face_mesh
|
| 15 |
|
| 16 |
self.face_mesh_images = mp_face_mesh.FaceMesh(static_image_mode=True, max_num_faces=1,
|
face_recognition/inference.py
CHANGED
|
@@ -24,15 +24,22 @@ class face_recognition:
|
|
| 24 |
# print(config_file_path)
|
| 25 |
self.model_config= importlib.import_module(config_file_path)
|
| 26 |
# print(self.model_config)
|
| 27 |
-
self.thres=thres if thres is not None else self.model_config.
|
| 28 |
self.aligner=aligner(min_aligner_confidence) if min_aligner_confidence is not None else aligner(config.min_aligner_confidence)
|
| 29 |
self.feature_extractor=tf.keras.models.load_model(model_path+"/model.h5",compile=False)
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
-
def euclidean_distance(self,vectors):
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
|
|
@@ -55,12 +62,12 @@ class face_recognition:
|
|
| 55 |
except:
|
| 56 |
raise AssertionError(f"db_face_features shape{db_face_features.shape} does not match crop_img_features shape{new_crop_img_features.shape}")
|
| 57 |
|
| 58 |
-
distance=np.
|
| 59 |
|
| 60 |
-
if distance
|
| 61 |
all_distances.append(distance) # obj distance wrt to all faces in database
|
| 62 |
else:
|
| 63 |
-
all_distances.append(self.model_config.large_distance) # not the person
|
| 64 |
return all_distances
|
| 65 |
|
| 66 |
|
|
@@ -69,8 +76,8 @@ class face_recognition:
|
|
| 69 |
faceidx_to_obj_dict=dict()
|
| 70 |
for obj in distance_dict.keys():
|
| 71 |
distances=np.array(distance_dict[obj])
|
| 72 |
-
min_distance,min_distance_idx = distances.
|
| 73 |
-
if min_distance
|
| 74 |
obj.find('name').text = self.faces[min_distance_idx]
|
| 75 |
distance_tag=ET.Element("distance")
|
| 76 |
distance_tag.text="{:.2f}".format(min_distance)
|
|
@@ -78,42 +85,43 @@ class face_recognition:
|
|
| 78 |
return faceidx_to_obj_dict
|
| 79 |
|
| 80 |
|
| 81 |
-
def assign_face_label(self,obj):
|
| 82 |
-
|
| 83 |
-
# find min and argmin
|
| 84 |
-
min_distance,min_distance_idx = self.distance_dict[obj].min(),self.distance_dict[obj].argmin()
|
| 85 |
-
# base condition
|
| 86 |
-
if min_distance>=self.thres:
|
| 87 |
-
# print("end");
|
| 88 |
-
return;
|
| 89 |
-
if min_distance_idx not in self.faceidx_to_obj_dict:
|
| 90 |
-
self.faceidx_to_obj_dict[min_distance_idx]=(obj,min_distance) # stores obj and distance
|
| 91 |
-
else:
|
| 92 |
-
|
| 93 |
-
if(min_distance>self.faceidx_to_obj_dict[min_distance_idx][1]):
|
| 94 |
-
self.distance_dict[obj][min_distance_idx]=self.model_config.large_distance
|
| 95 |
-
self.assign_face_label(obj)
|
| 96 |
-
else:
|
| 97 |
-
temp_obj,temp_min_distance=self.faceidx_to_obj_dict[min_distance_idx]
|
| 98 |
-
self.faceidx_to_obj_dict[min_distance_idx]=(obj,min_distance) # stores obj and distance
|
| 99 |
-
self.distance_dict[temp_obj][min_distance_idx]=self.model_config.large_distance
|
| 100 |
-
self.assign_face_label(temp_obj)
|
| 101 |
|
| 102 |
|
| 103 |
def no_repeat_allowed_face_recognition(self,distance_dict):
|
| 104 |
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
for obj in distance_dict.keys():
|
| 107 |
-
|
| 108 |
|
| 109 |
-
for idx,(obj,distance) in
|
| 110 |
obj.find('name').text = self.faces[idx]
|
| 111 |
distance_tag=ET.Element("distance")
|
| 112 |
distance_tag.text="{:.2f}".format(distance)
|
| 113 |
obj.append(distance_tag)
|
| 114 |
# print(obj.find("distance").text)
|
| 115 |
|
| 116 |
-
return
|
| 117 |
|
| 118 |
|
| 119 |
def forward_pass(self,img,tree,mode="repeat"):
|
|
|
|
| 24 |
# print(config_file_path)
|
| 25 |
self.model_config= importlib.import_module(config_file_path)
|
| 26 |
# print(self.model_config)
|
| 27 |
+
self.thres=thres if thres is not None else self.model_config.d_thres
|
| 28 |
self.aligner=aligner(min_aligner_confidence) if min_aligner_confidence is not None else aligner(config.min_aligner_confidence)
|
| 29 |
self.feature_extractor=tf.keras.models.load_model(model_path+"/model.h5",compile=False)
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
+
# def euclidean_distance(self,vectors):
|
| 34 |
+
# squared_sum=np.sum(np.square(vectors[0]-vectors[1]),axis=-1,keepdims=True)
|
| 35 |
+
# return np.sqrt(np.maximum(squared_sum,1e-7))
|
| 36 |
+
|
| 37 |
+
def new_distance(self,vectors):
|
| 38 |
+
''' this distance metric is -1 to 1
|
| 39 |
+
and it gives values close to 1 when matching
|
| 40 |
+
and values close to -1 when not matching
|
| 41 |
+
'''
|
| 42 |
+
return (vectors[0]*vectors[1]).sum(-1)
|
| 43 |
|
| 44 |
|
| 45 |
|
|
|
|
| 62 |
except:
|
| 63 |
raise AssertionError(f"db_face_features shape{db_face_features.shape} does not match crop_img_features shape{new_crop_img_features.shape}")
|
| 64 |
|
| 65 |
+
distance=np.max(self.new_distance([db_face_features,new_crop_img_features]),axis=0)
|
| 66 |
|
| 67 |
+
if distance>self.thres:
|
| 68 |
all_distances.append(distance) # obj distance wrt to all faces in database
|
| 69 |
else:
|
| 70 |
+
all_distances.append(self.model_config.large_distance) # not the person guaranteed
|
| 71 |
return all_distances
|
| 72 |
|
| 73 |
|
|
|
|
| 76 |
faceidx_to_obj_dict=dict()
|
| 77 |
for obj in distance_dict.keys():
|
| 78 |
distances=np.array(distance_dict[obj])
|
| 79 |
+
min_distance,min_distance_idx = distances.max(),distances.argmax()
|
| 80 |
+
if min_distance>self.thres:
|
| 81 |
obj.find('name').text = self.faces[min_distance_idx]
|
| 82 |
distance_tag=ET.Element("distance")
|
| 83 |
distance_tag.text="{:.2f}".format(min_distance)
|
|
|
|
| 85 |
return faceidx_to_obj_dict
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
def no_repeat_allowed_face_recognition(self,distance_dict):
|
| 91 |
|
| 92 |
+
def assign_face_label(obj):
|
| 93 |
+
|
| 94 |
+
# find min and argmin
|
| 95 |
+
min_distance,min_distance_idx = distance_dict[obj].max(),distance_dict[obj].argmax()
|
| 96 |
+
# base condition
|
| 97 |
+
if min_distance<self.thres:
|
| 98 |
+
# print("end");
|
| 99 |
+
return;
|
| 100 |
+
elif min_distance_idx not in faceidx_to_obj_dict:
|
| 101 |
+
faceidx_to_obj_dict[min_distance_idx]=(obj,min_distance) # stores obj and distance
|
| 102 |
+
else:
|
| 103 |
+
|
| 104 |
+
if(min_distance<faceidx_to_obj_dict[min_distance_idx][1]): # current is less matching
|
| 105 |
+
distance_dict[obj][min_distance_idx]=self.model_config.large_distance
|
| 106 |
+
assign_face_label(obj)
|
| 107 |
+
else: # current is more matching
|
| 108 |
+
temp_obj,temp_min_distance=faceidx_to_obj_dict[min_distance_idx]
|
| 109 |
+
faceidx_to_obj_dict[min_distance_idx]=(obj,min_distance) # stores obj and distance
|
| 110 |
+
distance_dict[temp_obj][min_distance_idx]=self.model_config.large_distance
|
| 111 |
+
assign_face_label(temp_obj)
|
| 112 |
+
|
| 113 |
+
faceidx_to_obj_dict=dict()
|
| 114 |
for obj in distance_dict.keys():
|
| 115 |
+
assign_face_label(obj)
|
| 116 |
|
| 117 |
+
for idx,(obj,distance) in faceidx_to_obj_dict.items():
|
| 118 |
obj.find('name').text = self.faces[idx]
|
| 119 |
distance_tag=ET.Element("distance")
|
| 120 |
distance_tag.text="{:.2f}".format(distance)
|
| 121 |
obj.append(distance_tag)
|
| 122 |
# print(obj.find("distance").text)
|
| 123 |
|
| 124 |
+
return faceidx_to_obj_dict
|
| 125 |
|
| 126 |
|
| 127 |
def forward_pass(self,img,tree,mode="repeat"):
|
setup_db.py
CHANGED
|
@@ -44,25 +44,25 @@ cursorObject.execute("""create table if not exists session_table(
|
|
| 44 |
);
|
| 45 |
""")
|
| 46 |
|
| 47 |
-
cursorObject.execute("""drop table if exists default_settings""")
|
| 48 |
-
cursorObject.execute("""create table if not exists default_settings(
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
""")
|
| 60 |
|
| 61 |
-
cursorObject.execute("""insert into default_settings(page,p_thres,nms_thres,small_size,large_size,d_thres,a_thres,db_mode,fr_mode) values(
|
| 62 |
-
|
| 63 |
|
| 64 |
-
cursorObject.execute("""insert into default_settings(page,p_thres,nms_thres,small_size,large_size,d_thres,a_thres,db_mode,fr_mode) values(
|
| 65 |
-
|
| 66 |
|
| 67 |
|
| 68 |
# cursorObject.execute("""drop table if exists user_settings""")
|
|
|
|
| 44 |
);
|
| 45 |
""")
|
| 46 |
|
| 47 |
+
# cursorObject.execute("""drop table if exists default_settings""")
|
| 48 |
+
# cursorObject.execute("""create table if not exists default_settings(
|
| 49 |
+
# page varchar(30) not null unique,
|
| 50 |
+
# p_thres float not null,
|
| 51 |
+
# nms_thres float not null,
|
| 52 |
+
# small_size integer not null default 544,
|
| 53 |
+
# large_size integer not null default 2080,
|
| 54 |
+
# d_thres float not null,
|
| 55 |
+
# a_thres float not null,
|
| 56 |
+
# db_mode enum('small','large','both') not null,
|
| 57 |
+
# fr_mode enum('small','large','both') not null
|
| 58 |
+
# );
|
| 59 |
+
# """)
|
| 60 |
|
| 61 |
+
# cursorObject.execute("""insert into default_settings(page,p_thres,nms_thres,small_size,large_size,d_thres,a_thres,db_mode,fr_mode) values(
|
| 62 |
+
# 'demo',0.5,0.3,256,1024,0.5,0.6,'small','large');""")
|
| 63 |
|
| 64 |
+
# cursorObject.execute("""insert into default_settings(page,p_thres,nms_thres,small_size,large_size,d_thres,a_thres,db_mode,fr_mode) values(
|
| 65 |
+
# 'user',0.7,0.3,544,2080,0.5,0.6,'small','both');""")
|
| 66 |
|
| 67 |
|
| 68 |
# cursorObject.execute("""drop table if exists user_settings""")
|
test.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
|
| 5 |
+
def euclidean_distance(vectors):
|
| 6 |
+
squared_sum=np.sum(np.square(vectors[0]-vectors[1]),axis=-1,keepdims=True)
|
| 7 |
+
return np.sqrt(np.maximum(squared_sum,1e-7))
|
| 8 |
+
|
| 9 |
+
def new_distance(vectors):
|
| 10 |
+
return (vectors[0]*vectors[1]).sum(-1)
|
| 11 |
+
|
| 12 |
+
path="face_recognition/Models/mobilenet_basic_lfw/mobilenet_basic_lfw_model.h5"
|
| 13 |
+
# path="face_recognition/Models/keras_mobilenet_emore_adamw/keras_mobilenet_emore_adamw.h5"
|
| 14 |
+
|
| 15 |
+
model2=tf.keras.models.load_model(path,compile=False)
|
| 16 |
+
|
| 17 |
+
x_input=tf.keras.layers.Input(shape=(112,112,3))
|
| 18 |
+
x_preprocess=tf.keras.layers.Lambda(lambda x:(x - 127.5) * 0.0078125)(x_input)
|
| 19 |
+
x=model2(x_preprocess,training=False)
|
| 20 |
+
x=tf.keras.layers.Lambda(lambda x:tf.math.l2_normalize(x, axis=-1))(x)
|
| 21 |
+
model2=tf.keras.Model(x_input,x)
|
| 22 |
+
# model2.summary()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# cv2.imread("")
|
| 26 |
+
# for layer in model2.layers:
|
| 27 |
+
# if isinstance(layer,tf.keras.layers.Activation):
|
| 28 |
+
# print(layer.activation)
|
| 29 |
+
|
| 30 |
+
img1=cv2.resize(cv2.imread("C:/Users/Home/Desktop/college stuff/vasu_dataset/all/priyanshi/7.jpg")[:,:,::-1],[112,112])[None]
|
| 31 |
+
img2=cv2.resize(cv2.imread("C:/Users/Home/Desktop/college stuff/vasu_dataset/all/shivansh/12.jpg")[:,:,::-1],[112,112])[None]
|
| 32 |
+
v1=(model2.predict(img1,verbose=0))
|
| 33 |
+
v2=(model2.predict(img2,verbose=0))
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
print("euclidean_distance:",euclidean_distance([v1,v2]))
|
| 37 |
+
print("new_distance:",new_distance([v1,v2]))
|
| 38 |
+
if(new_distance([v1,v2])[0]>0.2830035090446472):
|
| 39 |
+
print("matching")
|
| 40 |
+
else:
|
| 41 |
+
print("not matching")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
model2.save(path.rsplit("/",1)[0]+"/model.h5")
|
| 46 |
+
print("model save to :\t",path.rsplit("/",1)[0]+"/model.h5")
|