Spaces:
Paused
Paused
File size: 1,292 Bytes
7a6cb13 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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))
|