新书速览|PyTorch深度学习与企业级项目实战-CSDN博客
一套基本的人脸识别系统主要包含三部分:检测器、识别器和分类器,流程架构如图11-3所示:
图11-5
检测器负责检测图片中的人脸,再将检测出来的人脸感兴趣区域(Region of Interests,ROI)导入识别器中,识别器输出结果为一组特征向量。再通过分类器对特征向量进行分类匹配,最终得出人脸结果。
识别器采用FaceNet,一个有一定历史的源自谷歌的人脸识别系统,如图11-6所示:
图11-6
FaceNet只负责提取128维的人脸特征向量,通过对比输入人脸向量与数据库中人脸向量的欧式距离来确定人脸的相似性。通常可以通过实验拟定合适的距离阈值直接判断出人脸类别。谷歌人脸识别算法发表于CVPR 2015,利用相同人脸在不同角度等姿态的照片下有高内聚性,不同人脸有低耦合性,在LFW数据集上准确度达到99.63%。
通过神经网络将人脸映射到欧式空间的特征向量上,实质上不同图片的人脸特征距离较大,而通过相同个体的人脸距离总是小于不同个体的人脸。测试时只需要计算人脸特征,然后计算距离,使用阈值即可判定两幅人脸照片是否属于相同的个体。人脸识别的关键在于如何通过神经网络生成一个“好”的特征。特征的“好”体现在两点:(1)同一个人的人脸特征要尽可能相似;(2)不同人的人脸之间的特征要尽可能不同。
本项目使用FaceNet进行识别,执行pip install facenet-pytorch命令即可安装并使用它。项目代码如下:
############face_demo.py#############################
import cv2
import torch
from facenet_pytorch import MTCNN, InceptionResnetV1
# 获得人脸特征向量
def load_known_faces(dstImgPath, mtcnn, resnet):
aligned = []
knownImg = cv2.imread(dstImgPath) # 读取图片
face = mtcnn(knownImg) # 使用mtcnn检测人脸,返回人脸数组
if face is not None:
aligned.append(face[0])
aligned = torch.stack(aligned).to(device)
with torch.no_grad():
known_faces_emb = resnet(aligned).detach().cpu()
# 使用ResNet模型获取人脸对应的特征向量
print("\n人脸对应的特征向量为:\n", known_faces_emb)
return known_faces_emb, knownImg
# 计算人脸特征向量间的欧氏距离,设置阈值,判断是否为同一张人脸
def match_faces(faces_emb, known_faces_emb, threshold):
isExistDst = False
distance = (known_faces_emb[0] - faces_emb[0]).norm().item()
print("\n两张人脸的欧式距离为:%.2f" % distance)
if (distance < threshold):
isExistDst = True
return isExistDst
if __name__ == '__main__':
# help(MTCNN)
# help(InceptionResnetV1)
# 获取设备
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
# mtcnn模型加载设置网络参数,进行人脸检测
mtcnn = MTCNN(min_face_size=12, thresholds=[0.2, 0.2, 0.3],
keep_all=True, device=device)
# InceptionResnetV1模型加载用于获取人脸特征向量
resnet = InceptionResnetV1(pretrained='vggface2').eval().to(device)
MatchThreshold = 0.8 # 人脸特征向量匹配阈值设置
known_faces_emb, _ = load_known_faces('zc1.jpg', mtcnn, resnet) # 已知人物图
faces_emb, img = load_known_faces('zc2.jpg', mtcnn, resnet) # 待检测人物图
isExistDst = match_faces(faces_emb, known_faces_emb, MatchThreshold) # 人脸匹配
print("设置的人脸特征向量匹配阈值为:", MatchThreshold)
if isExistDst:
boxes, prob, landmarks = mtcnn.detect(img, landmarks=True)
print('由于欧氏距离小于匹配阈值,故匹配')
else:
print('由于欧氏距离大于匹配阈值,故不匹配')
第一次运行时系统需要下载预训练的VGGFace模型,时间会比较久,耐心等待,下载好之后程序便可以运行。# InceptionResnetV1提供了两个预训练模型,分别在VGGFace数据集和CASIA数据集上训练。如果不手动下载预训练模型,可能速度会很慢,可以从作者提供的源代码文件链接中下载,然后放到C:\Users\你的用户名\.cache\torch\checkpoints这个文件夹下面,如图11-7所示。
图11-7
代码运行结果如下:
人脸对应的特征向量为:
tensor([[ 3.4712e-03, -3.3803e-02, -7.4551e-02, 7.5545e-02, 7.5004e-02,
7.5054e-03, -1.1760e-02, 1.3724e-02, 2.9202e-02, 5.3316e-02,
1.3890e-02, 8.5973e-02, -8.5628e-03, 4.9886e-02, 2.6489e-02,
-1.5661e-02, -2.7966e-02, 5.9841e-02, 1.9875e-02, 4.4145e-02,
-3.8277e-02, 6.3352e-02, 6.5592e-02, 1.3518e-02, -1.7316e-02,
1.3677e-02, 2.1489e-02, -1.1110e-02, 1.4838e-02, -1.0393e-02,
7.0776e-02, -3.2754e-02, 2.2540e-02, -1.8506e-02, -1.9477e-02,
-4.7479e-02, -1.2302e-03, -5.0117e-03, 3.5990e-02, -9.0720e-03,
-8.1514e-03, -5.0032e-02, -2.3264e-02, -3.3499e-02, -1.7490e-02,
4.3102e-02, -3.9035e-02, 8.8361e-03, -5.2136e-02, -9.1468e-04,
-8.5388e-03, -6.3564e-02, -5.1791e-04, -3.2890e-02, -7.9093e-02,
-5.0719e-02, -1.1110e-02, -4.9189e-02, -2.0680e-03, -2.3497e-03,
-7.7022e-02, 2.4051e-02, -1.3201e-02, 8.0112e-02, -5.0470e-02,
-7.0014e-02, -2.2578e-02, -9.8802e-02, 1.2541e-02, -5.2823e-03,
1.2307e-02, -4.3561e-02, 4.5760e-02, 2.9625e-02, -2.4959e-02,
-1.5799e-02, 1.4963e-02, -7.9891e-02, 3.4688e-02, 1.5924e-02,
9.3366e-02, 3.6111e-02, -2.9158e-02, 1.8033e-02, 3.4338e-02,
3.7300e-02, 2.0125e-02, -1.0753e-03, -8.9421e-02, -9.8763e-02,
-3.3596e-02, 2.0461e-02, 5.0027e-02, 8.8703e-03, 3.8564e-02,
1.8740e-02, -4.0503e-02, 1.7464e-02, -4.8448e-04, 4.4506e-02,
-4.4170e-04, 1.4100e-01, 4.5607e-02, 4.6109e-02, 4.2329e-02,
-7.9481e-02, -1.1044e-01, -2.4543e-03, 7.3707e-02, -4.9287e-02,
8.2310e-02, 3.9243e-03, -7.2473e-02, -3.7786e-02, 7.9528e-02,
1.8944e-02, 2.4414e-02, 1.4515e-02, -3.6526e-02, 9.5348e-03,
4.8868e-02, 3.5857e-02, -1.6123e-02, -6.1225e-02, -2.2047e-02,
-6.8096e-02, -5.9098e-03, -2.9152e-02, -2.1959e-02, -7.3231e-04,
2.9521e-02, -8.0764e-03, -8.6338e-03, 1.3893e-02, -6.6358e-02,
3.6964e-02, -4.1740e-02, -2.1569e-02, 6.0459e-02, 5.6198e-02,
-1.0000e-02, 7.9048e-02, 1.8190e-02, 4.3672e-02, 8.1334e-02,
-1.4208e-02, -6.8403e-02, 5.3036e-02, 1.8395e-02, -8.4915e-02,
-2.6152e-02, 9.5801e-02, 7.3242e-02, 2.6583e-02, 4.5711e-02,
-5.9471e-02, -1.8299e-02, -6.8616e-04, -7.9323e-02, -7.8583e-02,
-3.6152e-02, 1.1124e-01, 8.0861e-02, -1.7114e-03, 3.8282e-02,
3.5957e-03, -6.7545e-02, 4.5646e-02, -8.6869e-02, 3.4204e-02,
-4.9498e-02, -3.8200e-02, 3.6278e-02, 6.1690e-02, 3.6768e-02,
4.0497e-04, -5.4611e-02, -1.7523e-02, 2.1868e-02, 1.0319e-01,
-1.7310e-02, -2.6656e-02, -1.2165e-02, -2.8046e-02, 3.4157e-02,
-6.2800e-02, 3.5509e-02, -1.4521e-02, 2.5019e-02, -1.3455e-02,
-2.9445e-02, 1.3143e-02, 8.3214e-02, -5.0222e-02, 8.8294e-02,
1.0487e-02, -2.0828e-03, -1.5776e-04, 1.1557e-01, 1.4953e-02,
4.2888e-02, -4.3941e-02, 3.3829e-02, -3.1209e-02, 3.6571e-02,
7.2716e-02, 8.3445e-02, 2.4947e-02, 6.6497e-02, 2.0023e-02,
-5.7615e-02, 4.6123e-02, -9.6370e-02, 1.1916e-02, 5.4752e-02,
2.4156e-02, 1.0516e-02, -7.6486e-03, -5.4590e-03, -1.0286e-01,
-3.4362e-02, 5.3673e-02, 9.6598e-02, 1.5524e-02, 6.0048e-02,
-3.1932e-02, 1.2479e-02, 1.4820e-02, 3.7208e-02, 4.7004e-03,
-1.2072e-02, -3.8017e-03, 5.7814e-02, 4.3031e-02, -1.0234e-01,
-4.0055e-02, -4.5796e-02, 2.1736e-02, 1.4845e-02, -1.0225e-02,
-3.2427e-02, -3.2377e-02, 3.5645e-02, -1.2190e-02, 1.3893e-02,
6.4499e-02, -3.5796e-02, 1.4229e-03, -3.2987e-02, 1.0370e-01,
9.2418e-05, -1.8383e-02, 7.1419e-02, 5.3676e-02, 4.5715e-02,
-4.5501e-02, -2.5915e-02, 1.7897e-02, -4.8481e-03, -2.2899e-02,
-5.4019e-02, 1.6531e-02, -1.7085e-02, -6.7630e-02, 1.0292e-03,
-4.4776e-02, 8.1510e-02, -4.6853e-03, 1.6822e-02, -3.5400e-02,
-5.8967e-03, -3.2569e-02, 4.4981e-02, -1.1273e-04, -1.7494e-02,
5.1819e-02, 3.2711e-02, 5.1785e-02, 6.0825e-02, 7.0018e-02,
2.9881e-03, 5.5177e-02, -3.9564e-02, -2.8699e-03, 1.4459e-02,
1.8928e-02, 3.9220e-02, 6.5493e-03, 1.8913e-02, 2.3281e-02,
4.0304e-03, -5.3355e-02, 2.9071e-02, 3.0768e-02, -3.4391e-02,
-8.8883e-03, -4.4707e-02, -2.5808e-02, -2.0463e-03, -1.7883e-03,
2.6834e-02, 2.1719e-02, -5.5138e-02, 1.4883e-02, -5.5297e-02,
-3.4217e-02, -7.2052e-02, -1.8436e-02, -7.1524e-02, -5.4871e-02,
-2.5637e-02, 5.0495e-03, 1.4074e-02, 2.1003e-02, -2.6554e-02,
6.1106e-02, 4.8323e-02, -3.0888e-02, 8.5392e-02, 2.5423e-02,
1.9556e-02, 8.9286e-03, 2.1759e-02, 2.6935e-03, 9.2207e-03,
2.9400e-02, 2.7426e-03, 6.1220e-03, 1.1357e-02, -5.5365e-02,
5.1218e-02, -2.3966e-02, -9.8014e-03, 8.0428e-03, -1.6347e-02,
-1.5323e-02, 3.7302e-02, 2.0880e-02, -5.1151e-02, -1.3894e-02,
6.6548e-02, -7.1495e-02, 2.5595e-02, 1.9089e-02, 6.3270e-02,
-3.8050e-02, -4.9755e-02, 1.3743e-02, 1.4883e-02, 3.7567e-02,
1.2775e-02, -4.9430e-02, -8.9282e-02, 1.1917e-02, 4.7397e-02,
1.7761e-02, -6.3704e-02, -2.0663e-02, -2.7912e-02, -4.2707e-03,
8.8550e-02, -1.4987e-02, 3.7087e-02, 2.2866e-02, 3.4060e-02,
-3.4592e-02, -3.7405e-02, 4.2265e-02, -4.4635e-03, -4.4386e-02,
1.4204e-02, -3.2770e-02, 6.4905e-03, -9.2989e-03, 4.7099e-02,
2.7463e-02, -6.6242e-02, 8.2403e-02, 4.8436e-02, 1.7216e-02,
-6.0735e-02, 2.3040e-02, -2.2254e-02, 5.1864e-02, -2.0307e-02,
-1.0792e-01, -3.3750e-02, 2.6689e-02, -5.7332e-03, -8.2967e-04,
4.6697e-02, -1.6334e-02, 2.9543e-02, -2.4496e-02, 2.1921e-02,
2.3240e-02, -1.4525e-02, 2.2601e-02, 2.2617e-02, -3.7140e-02,
-3.3851e-02, -4.7095e-02, 2.6207e-03, 3.0973e-02, 7.7156e-02,
3.4665e-02, -3.5616e-02, 2.3516e-02, -1.1597e-02, -3.4695e-02,
2.9642e-02, -1.4072e-02, 6.6081e-02, -3.6626e-02, -8.2910e-03,
1.3723e-02, 6.4786e-02, 1.6623e-02, -4.0311e-02, -5.2634e-02,
4.3602e-02, -9.4985e-02, -4.2924e-02, -1.7968e-02, -8.9135e-02,
5.7779e-02, -8.6424e-03, -1.0302e-02, 3.1657e-02, -3.5029e-02,
4.2131e-04, 5.1457e-02, 9.1248e-03, 3.9546e-02, 7.8386e-03,
-3.5465e-02, -8.1556e-02, -1.0003e-01, -6.8449e-02, 3.6476e-02,
-3.2796e-02, 1.6833e-02, -7.9688e-02, 6.1305e-02, -7.5220e-02,
1.9414e-02, -9.1699e-02, -3.3003e-02, 4.9971e-02, -3.1834e-02,
-3.2838e-04, -2.4987e-03, -2.5868e-02, 8.7424e-02, 1.2464e-02,
5.1778e-02, -5.7321e-02, -3.4015e-02, 3.6176e-02, 6.6906e-02,
1.1446e-02, -3.2977e-03, -1.6945e-02, 1.4339e-02, -2.1911e-02,
-1.2849e-02, -1.7293e-02, -4.4014e-02, -4.5847e-03, 8.7002e-02,
-3.9319e-03, -1.5899e-02, -4.5852e-03, -5.4031e-02, -2.1963e-02,
5.3231e-02, 3.0550e-02, -4.2703e-02, 4.4543e-02, 5.8105e-02,
4.4346e-03, -1.7361e-02, -7.0564e-02, -9.4657e-03, -4.9938e-04,
-4.0879e-02, -5.6463e-02, 6.4034e-02, 4.1187e-02, -5.5260e-02,
1.2887e-03, -8.1408e-02, -8.0722e-03, 1.5459e-02, 3.4163e-02,
-2.7703e-02, -1.0575e-02, -1.5972e-02, -1.9349e-02, -4.1658e-02,
9.2060e-02, 2.2700e-02, -1.7610e-02, -3.7694e-02, 1.9363e-02,
1.3842e-02, 1.1259e-02, 2.5194e-02, -6.1979e-03, -4.2225e-02,
6.3576e-02, -1.6959e-02]])
人脸对应的特征向量为:
tensor([[ 2.8001e-02, -4.6077e-05, -8.6044e-02, 8.5878e-02, 1.2105e-02,
-1.1743e-02, -2.8434e-02, 2.5946e-02, 1.0828e-02, 6.5367e-02,
3.6724e-02, 6.4824e-02, 8.2241e-03, 9.5099e-03, 2.2028e-03,
-2.3738e-02, 2.4834e-02, 7.7580e-02, 3.4812e-02, 4.3633e-02,
-3.2765e-02, 3.9885e-02, 5.9815e-02, 1.1277e-02, -2.3647e-02,
3.7536e-02, 5.0182e-02, -5.0968e-03, 2.4181e-02, 1.4791e-02,
4.3609e-02, -4.8512e-02, -1.1197e-02, -2.4020e-02, -2.0909e-02,
-5.7400e-02, -9.0896e-03, -4.0099e-03, 4.6863e-02, -1.0574e-02,
-5.9283e-02, -2.6868e-02, -3.9322e-03, -4.4244e-02, -5.3695e-02,
2.7417e-02, -3.6391e-02, 2.2492e-02, -3.5143e-02, 1.7806e-02,
-2.6510e-02, -2.4131e-02, -9.5295e-03, -3.4147e-02, -5.8626e-02,
-5.3492e-02, -1.6725e-02, -3.8434e-02, -1.7274e-02, 2.8466e-02,
-6.2296e-02, 4.9834e-02, -9.2619e-03, 1.0047e-01, -1.7747e-02,
-9.0714e-02, -1.7906e-03, -9.1519e-02, 3.8298e-02, -7.9362e-03,
1.7983e-02, -1.3934e-02, 1.9208e-02, 3.2441e-02, -5.6252e-02,
-3.0753e-02, -1.9317e-02, -9.5464e-02, 6.0164e-02, -2.0689e-02,
7.0994e-02, 9.0183e-03, -8.8793e-03, 2.0696e-02, 4.3443e-03,
5.1779e-02, 4.6088e-03, -1.0106e-03, -5.2725e-02, -1.0548e-01,
-4.8897e-02, -1.0818e-03, -9.9422e-03, 1.4751e-02, 3.4162e-02,
4.8421e-02, -2.1901e-02, -2.5356e-02, 8.7458e-04, 3.5136e-02,
-3.2679e-02, 7.7972e-02, -2.1496e-05, 4.7958e-02, 2.2844e-02,
-6.9589e-02, -1.0902e-01, -1.5985e-02, 8.7188e-02, -4.6646e-02,
8.5832e-02, -9.0789e-03, -4.7404e-02, -2.0494e-02, 6.4542e-02,
2.5289e-02, 2.4326e-02, 1.5756e-02, -4.7487e-02, 3.0095e-02,
5.3957e-02, 2.2976e-02, -4.5339e-03, -8.1201e-02, -3.0597e-02,
-6.6562e-02, -3.5471e-02, 4.2806e-03, -5.4908e-02, 2.2752e-02,
2.8738e-03, -3.5329e-03, -1.2144e-03, -7.9320e-03, -6.0214e-02,
4.0719e-02, -8.9511e-02, -2.3487e-02, 8.8598e-02, 7.5303e-02,
-4.9462e-03, 7.4318e-02, 5.5460e-02, 1.6797e-02, 1.8018e-02,
-4.0053e-03, -2.8476e-02, 5.7993e-02, 9.9384e-03, -3.0882e-02,
-3.1575e-03, 9.4481e-02, 1.0394e-01, 5.9584e-02, 4.4566e-02,
-3.8702e-02, -4.5532e-03, -1.4591e-02, -6.5482e-02, -1.0086e-01,
4.6935e-04, 1.2199e-01, 5.9991e-02, 1.6303e-02, 5.4855e-02,
1.7330e-02, -5.1591e-02, 2.5368e-02, -9.6256e-02, 3.8214e-02,
-4.3455e-02, -2.4861e-02, 3.5985e-02, 6.8475e-02, 1.2026e-02,
-9.9927e-03, -6.3830e-02, 3.2833e-03, 4.9050e-02, 7.7482e-02,
-4.6971e-02, -5.6034e-02, 2.6599e-02, -2.2255e-02, 9.3106e-03,
-3.9567e-02, 3.4344e-02, 2.5991e-03, 9.1569e-03, -1.6013e-02,
-3.8360e-02, 4.3487e-02, 6.6085e-02, -6.4094e-02, 6.5429e-02,
1.5000e-02, -8.1782e-03, -1.1519e-02, 1.2608e-01, 1.5738e-02,
3.0941e-02, -2.9139e-02, 5.4905e-03, -2.6635e-02, 5.8483e-02,
6.4671e-02, 5.2725e-02, 9.4255e-03, 1.0127e-03, -2.6401e-02,
-5.4639e-02, 5.2554e-02, -6.1758e-02, 5.3113e-03, 4.4088e-02,
-3.7597e-04, 4.3199e-02, 1.7960e-02, -1.3194e-02, -5.3666e-02,
-6.9236e-03, 1.5228e-02, 9.5189e-02, 1.7121e-03, 6.8666e-02,
-3.1494e-02, -3.2710e-03, 1.2875e-02, 3.4104e-02, -3.8668e-02,
4.4438e-02, 3.5936e-02, 6.5294e-02, 6.5020e-03, -9.5694e-02,
-3.1024e-02, -3.1105e-02, 2.8933e-02, 1.6933e-02, -4.2038e-02,
-2.2099e-02, -4.0839e-02, 1.6231e-02, 6.4055e-03, 1.2622e-02,
9.8138e-02, -3.8260e-02, 1.9346e-02, -1.6628e-02, 7.9439e-02,
-5.8328e-02, -3.7586e-02, 1.1977e-01, 1.0376e-01, -1.4088e-02,
-5.4806e-02, -2.4990e-02, -3.7368e-03, 2.6588e-03, -3.4183e-02,
-2.8388e-02, -2.4430e-02, 2.8746e-04, -8.2331e-02, -2.0489e-02,
-5.1880e-02, 5.3990e-02, -1.4081e-02, 3.8996e-03, -2.5366e-02,
4.9491e-02, -6.7067e-03, 8.1581e-02, 1.2502e-02, -3.7829e-02,
8.7758e-02, 4.0540e-03, 4.1892e-02, 4.1741e-02, 6.2050e-02,
-1.7033e-02, 1.1103e-02, -4.8190e-02, 9.1191e-03, -1.5349e-02,
2.0369e-02, 6.2642e-02, 1.5497e-02, -1.5949e-02, 3.3638e-02,
8.8257e-03, -8.7432e-02, -5.3558e-03, 6.4241e-02, -4.6744e-02,
-3.7447e-02, -6.5905e-02, -1.4245e-02, 1.9195e-02, -1.3502e-02,
3.8576e-02, -1.1787e-02, -4.9214e-02, 9.7343e-04, -3.1113e-02,
-4.3715e-02, -6.7970e-02, 1.3680e-02, -6.4623e-02, -2.9799e-02,
2.6732e-03, -2.3677e-02, -1.6467e-02, -1.2414e-03, 1.2750e-02,
6.1157e-02, 5.3833e-02, -5.2372e-02, 7.1081e-02, -1.0693e-03,
1.5802e-02, 1.1936e-02, 2.0765e-02, 3.6627e-02, -2.6504e-02,
6.5030e-02, -4.0269e-03, 2.0489e-02, 3.1264e-02, -2.9688e-02,
7.1595e-02, -1.6170e-02, -5.0382e-02, 1.2086e-02, 2.2211e-02,
3.3537e-03, 2.8533e-02, 2.5651e-02, -5.6540e-02, 2.8919e-02,
8.2882e-02, -7.6872e-02, 6.9056e-03, 3.1206e-03, 6.0089e-02,
-4.2560e-02, -4.1194e-02, 6.5368e-03, 6.3556e-02, 3.4444e-02,
-3.1026e-03, -3.2624e-02, -6.8420e-02, 7.6541e-03, 1.9499e-02,
9.8220e-03, -3.1817e-02, -9.2633e-03, -2.8895e-02, -3.6124e-03,
8.4322e-02, -8.4235e-03, -3.9177e-03, -1.0832e-02, 3.7069e-02,
-1.2210e-02, 3.5650e-03, 2.3400e-02, -1.0070e-02, -1.2330e-02,
-2.6249e-02, 1.1307e-02, 2.9681e-02, 1.0270e-02, 5.4042e-02,
3.2318e-02, -4.4361e-02, 8.5483e-02, 3.6199e-02, -5.7362e-03,
-3.2866e-02, 5.1268e-02, -9.7324e-03, 4.6712e-02, 4.2681e-02,
-1.0453e-01, -2.4820e-02, 3.1826e-02, -2.5282e-02, 1.2976e-02,
3.3787e-02, 1.1713e-02, -8.3608e-03, -1.2042e-02, -4.8544e-03,
1.6575e-02, -5.0426e-02, 2.8680e-02, 7.1943e-03, -4.2859e-02,
-1.7035e-02, -5.9024e-02, 1.4097e-02, 9.7493e-02, 6.5659e-02,
2.6462e-03, -2.1700e-02, 7.4545e-02, -1.7424e-02, -4.3287e-02,
3.1562e-02, -1.2064e-02, 4.6029e-02, 1.3218e-02, -3.2940e-02,
7.2298e-03, 7.4362e-02, 3.6358e-02, -3.6902e-02, -2.6793e-02,
7.4914e-02, -6.0268e-02, -2.9347e-02, -4.2823e-03, -6.4462e-02,
6.5568e-02, 1.7965e-02, 1.7363e-03, 4.5535e-02, 1.1650e-02,
4.7064e-03, 2.4497e-02, 2.7262e-02, 3.6480e-02, -2.0350e-03,
1.1950e-02, -1.1192e-01, -1.1854e-01, -5.0924e-02, 7.2288e-02,
-3.8969e-02, 4.4379e-02, -5.6238e-02, 6.4599e-02, -4.2769e-02,
1.8890e-02, -8.2483e-02, 1.4416e-02, 3.6263e-02, -3.8993e-02,
-5.0189e-03, 1.3234e-02, 2.6716e-02, 4.9479e-02, 2.4546e-02,
3.7020e-02, -5.9830e-02, -1.0016e-02, 2.8100e-02, 5.8243e-02,
3.1159e-02, 2.1257e-02, 4.0994e-03, 5.2662e-02, -2.8711e-02,
-1.1740e-02, 4.3464e-02, -3.5842e-02, -1.3946e-02, 6.7004e-02,
2.5971e-02, -3.0337e-02, 4.0123e-02, -2.6934e-02, -2.5729e-02,
6.9189e-02, 1.7639e-02, -5.9500e-02, 1.1843e-02, 3.1991e-02,
2.6366e-02, -1.7352e-02, -1.4246e-02, 1.0515e-02, -3.0290e-02,
3.1455e-03, -8.3119e-02, 1.1637e-01, 1.3950e-02, -3.6570e-02,
2.8140e-02, -6.3659e-02, -3.9275e-02, 3.3421e-02, 6.9780e-02,
-3.6235e-02, 1.4426e-02, 8.4869e-03, -2.3933e-02, -7.7233e-02,
1.1017e-01, 2.0508e-02, -9.7736e-03, -1.3255e-02, 1.7960e-02,
-2.6698e-03, -4.5193e-02, 6.5456e-02, -7.4565e-03, -3.5809e-02,
6.0265e-02, 1.3327e-02]])
两张人脸的欧式距离为:0.54。
设置的人脸特征向量匹配阈值为:0.8。
由于欧氏距离小于匹配阈值,故匹配。
《PyTorch深度学习与企业级项目实战(人工智能技术丛书)》(宋立桓,宋立林)【摘要 书评 试读】- 京东图书 (jd.com)