import json import time from deepface import DeepFace images_path = "/opt/data/face" # ========== 2. 人脸相似度比对 ========== start_time = time.time() result_verification = DeepFace.verify( img1_path=images_path + "/4.webp", img2_path=images_path + "/5.webp", model_name="ArcFace", # 指定模型 detector_backend="yolov11n", # 人脸检测器 retinaface / yolov8 / opencv / ssd / mediapipe distance_metric="cosine" # 相似度度量 ) end_time = time.time() print(f"🕒 人脸比对耗时: {end_time - start_time:.3f} 秒") # 打印结果 print(json.dumps(result_verification, ensure_ascii=False, indent=2)) # ========== 1. 人脸识别 ========== start_time = time.time() result_recognition = DeepFace.find( img_path=images_path + "/1.jpg", # 待识别人脸 db_path=images_path, # 数据库路径 model_name="ArcFace", # 指定模型 detector_backend="yolov11n", # 人脸检测器 distance_metric="cosine" # 相似度度量 ) end_time = time.time() print(f"🕒 人脸识别耗时: {end_time - start_time:.3f} 秒") # 如果需要打印结果,可以取消注释 # df = result_recognition[0] # print(df.to_json(orient="records", force_ascii=False))