PyTorch人脸识别

新书速览|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 = Falsedistance = (known_faces_emb[0] - faces_emb[0]).norm().item()print("\n两张人脸的欧式距离为:%.2f" % distance)if (distance < threshold):isExistDst = Truereturn isExistDstif __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)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/46704.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第二届大数据、计算智能与应用国际会议(BDCIA2024)

会议日期&#xff1a;2024年11月15-17日 会议地点&#xff1a;中国-湖北省-黄冈市 主办单位&#xff1a;黄冈师范学院 【大会主席】 【主讲嘉宾】 大会邀请到来自美国、英国、加拿大、新加坡、意大利、越南等10余位领域内学术大咖作主题报告&#xff0c;并与参会人员互动交…

鸿蒙开发:Universal Keystore Kit(密钥管理服务)【查询密钥是否存在(ArkTS)】

查询密钥是否存在(ArkTS) HUKS提供了接口供应用查询指定密钥是否存在。 开发步骤 指定密钥别名keyAlias&#xff0c;密钥别名最大长度为64字节。初始化密钥属性集。用于查询时指定密钥的属性TAG&#xff0c;比如查询的密钥范围(全量/单个)&#xff0c;当查询单个时&#xff…

分布式IO系统BL201 Profinet耦合器

BL201耦合器是一个数据采集和控制系统&#xff0c;基于强大的32 位微处理器设计&#xff0c;采用Linux操作系统&#xff0c;是一种模块化的分布式I/O系统。该系统由3部分组成&#xff1a;现场总线耦合器和各种类型的&#xff08;数字和模拟信号以及特殊功能&#xff09;I/O模块…

Ubuntu18 中JDK的安装

文章目录 一、背景说明二、获取安装包三、安装JDK3.1 上传安装包3.2 复制和解压3.3 环境变量的设置3.4 验证安装 四、问题列表4.1 .bashrc文件在哪里&#xff1f;.bashrc是什么&#xff1f;4.2 为什么使用rz上传安装包时会报&#xff1a; 传输失败&#xff1f; 五、总结 一、背…

解决RuntimeError: Couldn‘t load custom C++ ops. This can happen if your PyTorch

问题描述 刚下好yolov8的代码&#xff0c;想测一下能否成果&#xff0c;果然没成功&#xff0c;报错如下 RuntimeError: Couldnt load custom C ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling tor…

kettle从入门到精通 第七五课 ETL之kettle血缘,数据血缘

在了解kettle血缘之前&#xff0c;咱们先来了解下什么是数据血缘&#xff1f; 1、数据血缘定义&#xff08;来自gpt&#xff09; 数据血缘&#xff08;Data Lineage&#xff09;是指在数据管理和数据分析中追踪数据的源头、流向和处理过程的能力。具体来说&#xff0c;数据血…

《昇思25天学习打卡营第21天|基于 MindSpore 实现 BERT 对话情绪识别》

#学习打卡第21天# 1. BERT 模型 BERT全称是来自变换器的双向编码器表征量&#xff08;Bidirectional Encoder Representations from Transformers&#xff09;&#xff0c;它是Google于2018年末开发并发布的一种新型语言模型&#xff0c;是基于Transformer中的Encoder并加上双向…

org/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorkbook$Factory

org/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorkbook$Factory POI的问题 在操作Excel时&#xff0c;出现这个问题是因为缺少了poi-ooxml-schema jar包&#xff0c;并且与poi的jar包版本一致

昇思25天学习打卡营第21天 | 基于MindSpore的红酒分类实验

内容简介 本实验介绍了使用MindSpore框架实现K近邻算法&#xff08;KNN&#xff09;对红酒数据集进行分类的全过程。通过数据读取、预处理、模型构建与预测&#xff0c;展示了KNN算法在红酒数据集上的应用。实验中详细解释了KNN的原理、距离度量方式及其在分类问题中的应用&…

PyTorch张量创建和随机数生成器算法

文章目录 1、基本创建方式1.1、根据已有数据创建张量1.2、根据已有数据创建张量1.3、根据已有数据创建张量 2、创建线性和随机张量2.1、创建线性空间的张量2.2、创建随机张量2.3、什么是随机数种子2.4、initial_seed()和manual_seed() 3、创建01张量3.1、全0张量3.2、全1张量3.…

【Java18】初始化块

初始化块和构造器、成员变量、成员方法一起&#xff0c;是唯四能在类中出现的成员。 初始化块的作用和构造器类似&#xff0c;目的是对对象进行初始化操作&#xff1b;一个类中可以有多个初始化块&#xff1b;初始化块只有两种修饰方式&#xff1a;static和default。用static修…

nginx生成自签名SSL证书配置HTTPS

一、安装nginx nginx必须有"--with-http_ssl_module"模块 查看nginx安装的模块&#xff1a; rootecs-7398:/usr/local/nginx# cd /usr/local/nginx/ rootecs-7398:/usr/local/nginx# ./sbin/nginx -V nginx version: nginx/1.20.2 built by gcc 9.4.0 (Ubuntu 9.4.0…

Android Studio - adb.exe已停止运作的解决方案

adb.exe 是Android Debug Bridge 的缩写&#xff0c;它是Android SDK 中的一个调试工具&#xff0c;允许开发者通过命令行界面与设备进行交互&#xff0c;执行各种操作&#xff0c;如运行设备的shell、管理模拟器或设备的端口映射、在计算机和设备之间上传/下载文件、将本地APK…

我的GeneFace++部署与运行之旅

文章目录 引言项目背景概述重要性分析结论 环境准备1. 安装CUDA2. 安装Python依赖3. 准备3DMM模型&#xff08;BFM2009&#xff09;及其他数据 运行官方 Demo训练自己的视频数据准备训练推理测试 遇到的问题与解决方案问题一&#xff1a;cuda 安装完发现版本不对问题二&#xf…

C语言 底层逻辑详细阐述结构体 #结构体的声明 #结构体的初始化 #结构体成员访问 #结构体传参

文章目录 前言 一、结构体的基础知识 二、结构体的初始化 1、结构体类型声明&#xff1a; 2、结构体成员的类型 3、结构体变量的初始化&#xff1a; 三、结构体成员访问 四、结构体传参 总结 前言 基于自我理解的角度来讲结构体&#xff1b; 一、结构体的基础知识 结构是一些…

NSSCTF中24网安培训day2中web题目

[SWPUCTF 2021 新生赛]ez_unserialize 这道题目考察php反序列化的知识点 打开题目&#xff0c;发现没有提示&#xff0c;我们试着用御剑扫描目录文件&#xff0c;发现存在robots.txt的文件 接着访问这个文件&#xff0c;发现是一段php反序列化代码&#xff0c;我们需要进行序…

论文翻译:通过云计算对联网多智能体系统进行预测控制

通过云计算对联网多智能体系统进行预测控制 文章目录 通过云计算对联网多智能体系统进行预测控制摘要前言通过云计算实现联网的多智能体控制系统网络化多智能体系统的云预测控制器设计云预测控制系统的稳定性和一致性分析例子结论 摘要 本文研究了基于云计算的网络化多智能体预…

【常见开源库的二次开发】基于openssl的加密与解密——Base58比特币钱包地址——算法分析(三)

目录&#xff1a; 目录&#xff1a; 一、base58(58进制) 1.1 什么是base58&#xff1f; 1.2 辗转相除法 1.3 base58输出字节数&#xff1a; 二、源码分析&#xff1a; 2.1源代码&#xff1a; 2.2 算法思路介绍&#xff1a; 2.2.1 Base58编码过程&#xff1a; 2.1.2 Base58解码过…

Leetcode—146. LRU 缓存【中等】(shared_ptr、unordered_map、list)

2024每日刷题&#xff08;143&#xff09; Leetcode—146. LRU 缓存 先验知识 list & unordered_map 实现代码 struct Node{int key;int value;Node(int key, int value): key(key), value(value) {} };class LRUCache { public:LRUCache(int capacity): m_capacity(capa…

实战案例:用百度千帆大模型API开发智能五子棋

前随着人工智能技术的迅猛发展&#xff0c;各种智能应用层出不穷。五子棋作为一款经典的棋类游戏&#xff0c;拥有广泛的爱好者。将人工智能技术与五子棋结合&#xff0c;不仅能提升游戏的趣味性和挑战性&#xff0c;还能展现AI在复杂决策问题上的强大能力。在本篇文章中&#…