赞
踩
一、参考资料
https://zhuanlan.zhihu.com/p/43804018
二、实战
1、cd到如下目录:insightface/deploy/test.py,test.py的input是图片,output是人脸特征
2、复制test.py,并修改文件名为test_mines.py
3、修改test_mines.py
4、test_mines.py代码如下
- import face_model_mines
- import argparse
- import cv2
- import sys
- import numpy as np
-
- parser = argparse.ArgumentParser(description='face model test')
- # general
- parser.add_argument('--image-size', default='112,112', help='')
- parser.add_argument('--model', default='/data/tensorflow/WorkSpace/syd/FaceRecognition/Projects/insightface/recognition/models/model-r100-ii/r100-arcface-emore/model,0555', help='path to load model.')
- parser.add_argument('--ga-model', default='/data/tensorflow/WorkSpace/syd/FaceRecognition/Projects/insightface/models/gamodel-r50/model,0', help='path to load model.')
- parser.add_argument('--gpu', default=0, type=int, help='gpu id')
- parser.add_argument('--det', default=0, type=int, help='mtcnn option, 1 means using R+O, 0 means detect from begining')
- parser.add_argument('--flip', default=0, type=int, help='whether do lr flip aug')
- parser.add_argument('--threshold', default=1.24, type=float, help='ver dist threshold')
- args = parser.parse_args()
-
- ##模型载入
- model = face_model_mines.FaceModel(args)
-
- ##图片载入
- path_img1 = '/data/tensorflow/WorkSpace/syd/FaceRecognition/Projects/insightface/deploy/test/shenyanding1.jpg'
- path_img2 = '/data/tensorflow/WorkSpace/syd/FaceRecognition/Projects/insightface/deploy/test/shenyanding2.jpg'
-
- #提取图片名称:姓名
- s1 = path_img1.rfind('/', 1)+1
- s2 = path_img1.rfind('.',1)-1
- name_img1 = path_img1[s1:s2]
- print("被检测人姓名:",name_img1)
-
- ss1 = path_img2.rfind('/', 1)+1
- ss2 = path_img2.rfind('.',1)-1
- name_img2 = path_img2[ss1:ss2]
- print("比对人姓名:",name_img2)
-
- ##根据模型计算人脸特征向量
- img1 = cv2.imread(path_img1)
- img1 = model.get_input(img1)
- f1 = model.get_feature(img1)
- img2 = cv2.imread(path_img2)
- img2 = model.get_input(img2)
- f2 = model.get_feature(img2 )
-
- ##计算余弦距离
- dist1 = np.sum(np.square(f1-f2))
- dist1 = float("%.2f" % dist1)
-
- ##输出模型检测结果
- #检测逻辑:如果两张人脸的距离超过设定阈值则不是同一人,如果小于等于设定阈值则为同一人
- dist_yuzhi = 1.24
-
- if dist1<=dist_yuzhi:
- print("模型检测结果:是同一人")
- else:
- print("模型检测结果:不是同一人")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。