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 = 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)

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

音视频入门基础:H.264专题(13)——FFmpeg源码中通过SPS属性获取视频色彩格式的实现

一、引言 通过FFmpeg命令可以获取到H.264裸流文件的色彩格式&#xff08;又译作色度采样结构、像素格式&#xff09;&#xff1a; 在vlc中也可以获取到色彩格式&#xff08;vlc底层也使用了FFmpeg进行解码&#xff09;&#xff1a; 这个色彩格式就是之前的文章《音视频入门基础…

2024年初级注册安全工程师职业资格考试首次开考!

​2024年初级注册安全工程师考试首次开考&#xff08;注&#xff1a;该考试由各省人事考试局组织考试&#xff09;。目前未取得中级注册安全工程师证书的各位同学&#xff0c;可以关注该考试&#xff0c;毕竟初级考证相对较容易&#xff0c;先去考一个。 目前初安开考地区汇总…

【Diffusion学习】【生成式AI】Stable Diffusion、DALL-E、Imagen 背後共同的套路

文章目录 图片生成Framework 需要3个组件&#xff1a;相关论文【Stable Diffusion&#xff0c;DALL-E&#xff0c;Imagen】 具体介绍三个组件1. Text encoder介绍【结论&#xff1a;文字的encoder重要&#xff0c;Diffusion的模型不是很重要&#xff01;】评估指标&#xff1a;…

大数据面试SQL题-笔记01【运算符、条件查询、语法顺序、表连接】

大数据面试SQL题复习思路一网打尽&#xff01;(文档见评论区)_哔哩哔哩_bilibiliHive SQL 大厂必考常用窗口函数及相关面试题 大数据面试SQL题-笔记01【运算符、条件查询、语法顺序、表连接】大数据面试SQL题-笔记02【...】 目录 01、力扣网-sql题 1、高频SQL50题&#xff08…

基于Java的斗地主游戏案例开发(做牌、洗牌、发牌、看牌

package Game;import java.util.ArrayList; import java.util.Collections;public class PokerGame01 {//牌盒//♥3 ♣3static ArrayList<String> list new ArrayList<>();//静态代码块//特点&#xff1a;随着类的加载而在加载的&#xff0c;而且只执行一次。stat…

【C语言】深入解析选择排序

文章目录 什么是选择排序&#xff1f;选择排序的基本实现代码解释选择排序的优化选择排序的性能分析选择排序的实际应用结论 在C语言编程中&#xff0c;选择排序是一种简单且直观的排序算法。尽管它在处理大型数据集时效率不高&#xff0c;但由于其实现简单&#xff0c;常常用于…

2024-07-15 Unity插件 Odin Inspector4 —— Collection Attributes

文章目录 1 说明2 集合相关特性2.1 DictionaryDrawerSettings2.2 ListDrawerSettings2.3 TableColumnWidth2.4 TableList2.5 TableMatrix 1 说明 ​ 本文介绍 Odin Inspector 插件中集合&#xff08;Dictionary、List&#xff09;相关特性的使用方法。 2 集合相关特性 2.1 D…

直播美颜工具开发教学:视频美颜SDK集成详解

本篇文章&#xff0c;笔者将详细介绍如何在直播应用中集成视频美颜SDK&#xff0c;让你的直播画面焕然一新。 一、什么是视频美颜SDK&#xff1f; 视频美颜SDK是一种软件开发工具包&#xff0c;提供了视频处理和图像增强功能。通过集成视频美颜SDK&#xff0c;开发者可以轻松…

十九、【文本编辑器(五)】排版功能

目录 一、搭建框架 二、实现段落对齐 三、实现文本排序 一、搭建框架 (1) 在imgprocessor.h文件中添加private变量&#xff1a; QLabel *listLabel; //排序设置项QComboBox *listComboBox;QActionGroup *actGrp;QAction *leftAction;QAction *…

Win11鼠标卡顿 - 解决方案

问题 使用Win11系统使&#xff0c;鼠标点击任务栏的控制中心&#xff08;如下图&#xff09;时&#xff0c;鼠标会有3秒左右的卡顿&#xff0c;同时整个显示屏幕也有一定程度的卡顿。 问题原因 排除鼠标问题&#xff1a;更换过不同类型的鼠标&#xff0c;以及不同的连接方式…

昇思25天学习打卡营第22天|应用实践之DCGAN生成漫画头像

基本介绍 今日要实践的模型是DCGAN&#xff0c;用于生成漫画头像&#xff0c;生成头像原理可参考GAN图像生成。使用的动漫头像数据集共有70,171张动漫头像图片&#xff0c;图片大小均为96*96。本文会先简单介绍DCGAN模型&#xff0c;然后展示自己的运行结果&#xff0c;不作代码…

新增支持GIS地图、数据模型引擎升级、增强数据分析处理能力

为了帮助企业提升数据分析处理能力&#xff0c;Smartbi重点围绕产品易用性、用户体验、操作便捷性进行了更新迭代&#xff0c;同时重磅更新了体验中心。用更加匹配项目及业务需求的Smartbi&#xff0c;帮助企业真正发挥数据的价值&#xff0c;赋能决策经营与管理。 Smartbi用户…

端到端拥塞控制的本质

昨天整理了一篇 bbr 的微分方程组建模(参见 bbr 建模)&#xff0c;算是 bbr 算法终极意义上的一个总结&#xff0c;最后也顺带了对 aimd 的描述&#xff0c;算是我最近比较满意的一篇分享了。那么接下来的问题&#xff0c;脱离出具体算法&#xff0c;上升到宏观层面&#xff0c…

百度“文心•跨模态大模型”又有新动态,支持内容分析时输出自定义标签库

大模型真正的价值在于应用。 一、基本概念 AI大模型具有强大的表征学习能力&#xff0c;能够在海量数据中提取有用的特征&#xff0c;为各种复杂任务提供解决方案。例如GPT-4o、BERT等模型的出现&#xff0c;不仅展示了大规模参数和复杂计算结构的优势&#xff0c;还在自然语…

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

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

如何申请抖音本地生活服务商?3种方式优劣势分析!

随着多家互联网大厂在本地生活板块的布局力度不断加大&#xff0c;以抖音为代表的头部互联网平台的本地生活服务商成为了创业赛道中的大热门&#xff0c;与抖音本地生活服务商怎么申请等相关的帖子&#xff0c;更是多次登顶创业者社群的话题榜单。 就目前的市场情况来看&#x…

微信小程序,订阅消息

微信小程序&#xff0c;订阅消息&#xff0c;完整流程 1.选择需要的模版 2.前端调用订阅消息 注&#xff1a;tmplIds&#xff1a;模板ID模版id,这里也可以选多个 wx.requestSubscribeMessage({tmplIds: [7UezzOrfJg_NIYdE1p*******],success (res) { console.log(res);wx.g…

为什么要使用加密软件?

一、保护数据安全&#xff1a;加密软件通过复杂的加密算法对敏感数据进行加密处理&#xff0c;使得未经授权的人员即使获取了加密数据&#xff0c;也无法轻易解密和获取其中的内容。这极大地提高了数据在存储、传输和使用过程中的安全性。 二、遵守法律法规&#xff1a;在许多国…

axios 下载大文件时,展示下载进度的组件封装——js技能提升

之前面试的时候&#xff0c;有遇到一个问题&#xff1a;就是下载大文件的时候&#xff0c;如何得知下载进度&#xff0c;当时的回复是没有处理过。。。 现在想到了。axios中本身就有一个下载进度的方法&#xff0c;可以直接拿来使用。 下面记录一下处理步骤&#xff1a; 参考…

一款好用的特殊字符处理工具

跟mybatis代码的时候&#xff0c;偶然发现的一款特殊字符处理工具java.lang.StringTokenizer。平常&#xff0c;我们看到的mybatis mapper.xml里面各种换行各种缩进&#xff0c;但日志文件里面的sql都是整整齐齐的。没有换行符&#xff0c;缩进等。就是利用该工具做的格式化处理…