|
@@ -8,6 +8,9 @@ import numpy as np
|
|
|
import re
|
|
|
import os
|
|
|
import time
|
|
|
+import shlex
|
|
|
+import subprocess
|
|
|
+from face_recognition_svm import train_svm
|
|
|
|
|
|
ImageFile.SAFEBLOCK = 2048 * 2048
|
|
|
|
|
@@ -46,11 +49,16 @@ dummy_data = [
|
|
|
"address": "909 South St Paul Street Hopewell, VA 23860",
|
|
|
"nik": "1000075656784734"
|
|
|
},
|
|
|
+ {
|
|
|
+ "name": "Abi",
|
|
|
+ "address": "47 Rockville Road Leland, NC 28451",
|
|
|
+ "nik": "1000084937284959"
|
|
|
+ },
|
|
|
]
|
|
|
ssl = None
|
|
|
known_people = "application_data/verification_images"
|
|
|
known_faces = []
|
|
|
-total_threshold = 0.2
|
|
|
+total_threshold = 0.1
|
|
|
face_model = "large"
|
|
|
if face_model == "large":
|
|
|
model_file_name = "saved_model_2_large.pkl"
|
|
@@ -64,10 +72,8 @@ def scan_known_people(known_people_folder):
|
|
|
for file in image_files_in_folder(known_people_folder):
|
|
|
img = face_recognition.load_image_file(file)
|
|
|
encodings = face_recognition.face_encodings(img, model=face_model)
|
|
|
-
|
|
|
if len(encodings) > 1:
|
|
|
print("WARNING: More than one face found in {}. Only considering the first face.".format(file))
|
|
|
-
|
|
|
if len(encodings) == 0:
|
|
|
print("WARNING: No faces found in {}. Ignoring file.".format(file))
|
|
|
else:
|
|
@@ -82,12 +88,15 @@ def image_files_in_folder(folder):
|
|
|
img_list.sort()
|
|
|
return img_list
|
|
|
|
|
|
+
|
|
|
def load_db():
|
|
|
pass
|
|
|
|
|
|
-def save_db(name, address, nik):
|
|
|
+
|
|
|
+def save_db(nik, name, address):
|
|
|
pass
|
|
|
|
|
|
+
|
|
|
@app.route('/upload', methods=['POST'])
|
|
|
def upload():
|
|
|
profile = request.files["profile"]
|
|
@@ -95,7 +104,29 @@ def upload():
|
|
|
name = request.form["name"]
|
|
|
address = request.form["address"]
|
|
|
|
|
|
-
|
|
|
+@app.route('/train', methods=['GET', 'POST'])
|
|
|
+def train():
|
|
|
+ try:
|
|
|
+ train_svm(model_file_name)
|
|
|
+ return jsonify({"status": "0", "message": "Train successful"})
|
|
|
+ except Exception as exc:
|
|
|
+ return jsonify({"status": "1", "message": f"Error training model: {exc}"})
|
|
|
+
|
|
|
+@app.route('/reload', methods=['GET', 'POST'])
|
|
|
+def face_reload():
|
|
|
+ pid = None
|
|
|
+ try:
|
|
|
+ with open("app.pid", "r") as f:
|
|
|
+ pid = f.readline()
|
|
|
+ if pid:
|
|
|
+ cmd = f"kill -s HUP {pid}"
|
|
|
+ cmd_array = shlex.split(cmd)
|
|
|
+ print(cmd_array)
|
|
|
+ subprocess.Popen(cmd_array, start_new_session=True)
|
|
|
+ else:
|
|
|
+ return jsonify({"status": "1", "message": f"Reload unsucessful"})
|
|
|
+ except Exception as exc:
|
|
|
+ return jsonify({"status": "2", "message": f"Reload unsucessful: {exc}"})
|
|
|
|
|
|
|
|
|
@app.route('/predict', methods=['POST'])
|
|
@@ -154,6 +185,7 @@ def predict():
|
|
|
print(result)
|
|
|
return jsonify(result)
|
|
|
|
|
|
+
|
|
|
try:
|
|
|
clf = joblib.load(model_file_name)
|
|
|
classes = clf.classes_
|
|
@@ -165,6 +197,5 @@ except FileNotFoundError as e:
|
|
|
print('No model here')
|
|
|
exit(1)
|
|
|
|
|
|
-
|
|
|
if __name__ == '__main__':
|
|
|
app.run(host='0.0.0.0', port=8349, debug=True, ssl_context=ssl)
|