gehaocool / CombinedMargin-caffe

caffe implementation of insightface's combined margin method
92 stars 28 forks source link

关于人脸相似度的计算? #18

Closed xiaosuzhang closed 5 years ago

xiaosuzhang commented 5 years ago

您好,我使用您公布的训练好的模型,来测试C罗和梅西人脸之间的相似度,得到的相似度结果为0.95,是不是我选择的度量函数有问题呀? 以下是我的代码,还请您帮我看一下,指出我存在的问题,谢谢!!!

`import caffe import cv2 import numpy as np import sklearn.metrics.pairwise as pw

def read_image(img_path): averageImg = [127.5, 127.5, 127.5] X = np.empty((1, 3, 112, 96)) im1 = cv2.imread(img_path) image = cv2.resize(im1, (96, 112)) * 255 X[0, 0, :, :] = image[:, :, 0] - averageImg[0] X[0, 1, :, :] = image[:, :, 1] - averageImg[1] X[0, 2, :, :] = image[:, :, 2] - averageImg[2] return X net = caffe.Classifier('model/deploy.prototxt', 'model/inference.caffemodel', caffe.TEST)

X = read_image('image/12.jpg') test_num = np.shape(X)[0] out = net.forward_all(blobs=['fc5'], data=X) feature1 = np.float64(out["fc5"]) feature1 =np.reshape(feature1, (test_num, 512)) X = read_image('image/123.jpg') out = net.forward_all(blobs=['fc5'], data=X) feature2 = np.float64(out['fc5']) feature2 =np.reshape(feature2, (test_num, 512)) accuracy =pw.cosine_similarity(feature1,feature2) print(accuracy)`

gehaocool commented 5 years ago

你输入的两张图片是否经过对齐操作?

xiaosuzhang commented 5 years ago

没有对齐,直接进行人脸识别的???

gehaocool commented 5 years ago

需要先通过MTCNN进行人脸检测和5个特征点定位,再用这5个特征点将人脸对齐,并缩放至112×96的尺寸,再送入网络提取特征向量