insight face +windows+anaconda+mxnet-test.py

文章:InsightFace: 2D and 3D Face Analysis Project

 

反正就是很牛的一篇文章,能找到我这里肯定知道。

①配置MxNet环境,见我另外一篇博文。https://blog.csdn.net/chapmancp/article/details/79767659

②下载insightface源码。https://github.com/deepinsight/insightface#test-on-megaface

③下载训练好的模型。https://pan.baidu.com/s/1jKahEXw

这个是LResNet34E-IR 模型。放到models下。要与下面test.py里面的model路径一致,当然你也可以改成你放model的位置。

④打开deploy\test.py

自己找两张人脸图片,修改两张图片路径,就可以测试他们的相似度啦。最后输出两个值,第二个就是相似度。

 

后来在windows上装了python3.6+pytorch0.40.原先的insight face是python2.7.里面的几个包需要修改一下。

其中一个是from easydict import EasyDict as edict

重新pip

另外一个是from itertools import izip

因为2.7中的izip就是3。6里面的zip,so把上面这句话注释掉,并添加  izip = zip

import face_embedding
import argparse
import cv2
import numpy as np


#args参数设置
parser = argparse.ArgumentParser(description='face model test')
# general
parser.add_argument('--image-size', default='112,112', help='')
parser.add_argument('--model', default='../models/model-r50-am-lfw/model,0', help='path to load model.')

#parser.add_argument('--model', default='../models/model-r34-amf/model,0', help='path to load model.')

parser.add_argument('--gpu', default=0, type=int, help='gpu id')
parser.add_argument('--det', default=2, type=int, help='mtcnn option, 2 means using R+O, else using O')
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()

#根据args参数,初始化模型的class,
model = face_embedding.FaceModel(args)
#img = cv2.imread('/raid5data/dplearn/lfw/Jude_Law/Jude_Law_0001.jpg')

#计算第一个图片的特征,
img = cv2.imread('1.jpg')
f1 = model.get_feature(img)
#计算第二个图片的特征
img = cv2.imread('2.jpg')
f2 = model.get_feature(img)
#计算两张图片特征的差
dist = np.sum(np.square(f1-f2))
print(dist)
#计算两张图片相似度结果
sim = np.dot(f1, f2.T)
print(sim)
#diff = np.subtract(source_feature, target_feature)
#dist = np.sum(np.square(diff),1)

 

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 17
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值