【人脸识别】insightface 使用记录和搭建服务注意点和坑 从0到1

news2024/10/2 6:40:22

文章目录

  • 前言
  • 1.开始
    • 1.1 前置
    • 1.2 再次运行,人脸检测跑通
    • 1.3 人脸特征抽取
      • 1.3.1 模型下载
      • 1.3.2 重新跑一下检测和识别
      • 1.3.3 人脸监测返回值分析
      • 1.3.4 计算相似度
    • 1.4 全流程的相似度
  • 2. 业务化人脸识别


前言

人脸识别项目,再走一遍。之前是公司老人留下的,没部署过,没交付过。这次重新搞一个,并且把搞过的记录下来。


参考旷视的insightface:
https://github.com/deepinsight/insightface/tree/master/python-package
另外一个blog:https://blog.csdn.net/u013171226/article/details/123249453

创建环境,安装库

conda activate -n insightface python=3.8
pip install insightface

把它的git 代码都拉下来:
https://github.com/deepinsight/insightface
解压到 /home/jianming_ge/workplace/zhongwaiyun/insightface/

1.开始

1.1 前置

cd /home/jianming_ge/workplace/zhongwaiyun/insightface/python-package
pip install numpy opencv-python 
pip install onnxruntime-gpu

创建一个文件:
aaa.py

import cv2
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

app = FaceAnalysis(allowed_modules=['detection'],providers=['CUDAExecutionProvider', 'CPUExecutionProvider'],download=False)
app.prepare(ctx_id=0, det_size=(640, 640))
img = ins_get_image('ldh')  #不用带后缀,图片放到./insightface/python-package/insightface/data/images
faces = app.get(img)
print("faces::::", faces)
rimg = app.draw_on(img, faces)
cv2.imwrite("./ldh_output.jpg", rimg)

运行:python aaa.py
报错:

(insightface) [jianming_ge@localhost python-package]$ python aaa.py 
Traceback (most recent call last):
  File "aaa.py", line 3, in <module>
    import insightface
  File "/home/jianming_ge/workplace/zhongwaiyun/insightface/python-package/insightface/__init__.py", line 18, in <module>
    from . import app
  File "/home/jianming_ge/workplace/zhongwaiyun/insightface/python-package/insightface/app/__init__.py", line 2, in <module>
    from .mask_renderer import *
  File "/home/jianming_ge/workplace/zhongwaiyun/insightface/python-package/insightface/app/mask_renderer.py", line 8, in <module>
    from ..thirdparty import face3d
  File "/home/jianming_ge/workplace/zhongwaiyun/insightface/python-package/insightface/thirdparty/face3d/__init__.py", line 3, in <module>
    from . import mesh
  File "/home/jianming_ge/workplace/zhongwaiyun/insightface/python-package/insightface/thirdparty/face3d/mesh/__init__.py", line 9, in <module>
    from .cython import mesh_core_cython

解决:

 find  ./ -iname "cython"
 (insightface) [jianming_ge@localhost python-package]$ find  ./ -iname "cython"
./insightface/thirdparty/face3d/mesh/cython
(insightface) [jianming_ge@localhost python-package]$ cd ./insightface/thirdparty/face3d/mesh/cython/
(insightface) [jianming_ge@localhost cython]$ ls
mesh_core.cpp  mesh_core_cython.c  mesh_core_cython.cpp  mesh_core_cython.pyx  mesh_core.h  setup.py
(insightface) [jianming_ge@localhost python-package]$ cd ./insightface/thirdparty/face3d/mesh/cython/
(insightface) [jianming_ge@localhost cython]$ ls
mesh_core.cpp  mesh_core_cython.c  mesh_core_cython.cpp  mesh_core_cython.pyx  mesh_core.h  setup.py
(insightface) [jianming_ge@localhost cython]$ python setup.py build_ext -i
In file included from /home/jianming_ge/miniconda3/envs/insightface/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1940,
                 from /home/jianming_ge/miniconda3/envs/insightface/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/jianming_ge/miniconda3/envs/insightface/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from mesh_core_cython.cpp:780:
/home/jianming_ge/miniconda3/envs/insightface/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it with " \

到包文件下,执行一下安装就可以了
cd ./insightface/thirdparty/face3d/mesh/cython/
python setup.py build_ext -i

1.2 再次运行,人脸检测跑通

python aaa.py

(insightface) [jianming_ge@localhost python-package]$ python aaa.py 
download_path: /home/jianming_ge/.insightface/models/buffalo_l
Downloading /home/jianming_ge/.insightface/models/buffalo_l.zip from https://github.com/deepinsight/insightface/releases/download/v0.7/buffalo_l.zip...
  0%|| 208/281857 [00:01<43:44, 107.30KB/s]^Z
[2]+  已停止               python aaa.py

他去下载去了,不知为什么在从git上下载特别慢,所以放弃了,想法是手动下载好,传到它所需要的目录。
Downloading /home/jianming_ge/.insightface/models/buffalo_l.zip from https://github.com/deepinsight/insightface/releases/download/v0.7/buffalo_l.zip…
代码追踪后在这里,dir_path
在这里插入图片描述
位置:python-package/insightface/utils/storage.py
追踪到dir_path = ~/.insightface/models/buffalo_l
建好目录,并且把权重文件放进去

(insightface) [jianming_ge@localhost python-package]$ mkdir ~/.insightface/models/buffalo_l
(insightface) [jianming_ge@localhost python-package]$ cp ~/.insightface/models/*.onnx  ~/.insightface/models/buffalo_l/
(insightface) [jianming_ge@localhost python-package]$ ls ~/.insightface/models/buffalo_l
1k3d68.onnx  2d106det.onnx  det_10g.onnx  genderage.onnx  w600k_r50.onnx

import os
import os.path as osp
import zipfile
from .download import download_file

BASE_REPO_URL = 'https://github.com/deepinsight/insightface/releases/download/v0.7'

def download(sub_dir, name, force=False, root='~/.insightface'):
    _root = os.path.expanduser(root)
    dir_path = os.path.join(_root, sub_dir, name)
    if osp.exists(dir_path) and not force:
        return dir_path
    print('download_path:', dir_path)
    zip_file_path = os.path.join(_root, sub_dir, name + '.zip')
    model_url = "%s/%s.zip"%(BASE_REPO_URL, name)
    download_file(model_url,
             path=zip_file_path,
             overwrite=True)
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
    with zipfile.ZipFile(zip_file_path) as zf:
        zf.extractall(dir_path)
    #os.remove(zip_file_path)
    return dir_path

def ensure_available(sub_dir, name, root='~/.insightface'):
    return download(sub_dir, name, force=False, root=root)

def download_onnx(sub_dir, model_file, force=False, root='~/.insightface', download_zip=False):
    _root = os.path.expanduser(root)
    model_root = osp.join(_root, sub_dir)
    new_model_file = osp.join(model_root, model_file)
    if osp.exists(new_model_file) and not force:
        return new_model_file
    if not osp.exists(model_root):
        os.makedirs(model_root)
    print('download_path:', new_model_file)
    if not download_zip:
        model_url = "%s/%s"%(BASE_REPO_URL, model_file)
        download_file(model_url,
                 path=new_model_file,
                 overwrite=True)
    else:
        model_url = "%s/%s.zip"%(BASE_REPO_URL, model_file)
        zip_file_path = new_model_file+".zip"
        download_file(model_url,
                 path=zip_file_path,
                 overwrite=True)
        with zipfile.ZipFile(zip_file_path) as zf:
            zf.extractall(model_root)
        return new_model_file

再次执行:
python aaa.py
输出:

(insightface) [jianming_ge@localhost python-package]$ python aaa.py 
Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}, 'CUDAExecutionProvider': {'tunable_op_enabled': '0', 'cudnn_conv_use_max_workspace': '1', 'enable_cuda_graph': '0', 'do_copy_in_default_stream': '1', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv1d_pad_to_nc1d': '0', 'gpu_external_empty_cache': '0', 'gpu_external_free': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'device_id': '0'}}
model ignore: /home/jianming_ge/.insightface/models/buffalo_l/1k3d68.onnx landmark_3d_68
Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}, 'CUDAExecutionProvider': {'tunable_op_enabled': '0', 'cudnn_conv_use_max_workspace': '1', 'enable_cuda_graph': '0', 'do_copy_in_default_stream': '1', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv1d_pad_to_nc1d': '0', 'gpu_external_empty_cache': '0', 'gpu_external_free': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'device_id': '0'}}
model ignore: /home/jianming_ge/.insightface/models/buffalo_l/2d106det.onnx landmark_2d_106
Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}, 'CUDAExecutionProvider': {'tunable_op_enabled': '0', 'cudnn_conv_use_max_workspace': '1', 'enable_cuda_graph': '0', 'do_copy_in_default_stream': '1', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv1d_pad_to_nc1d': '0', 'gpu_external_empty_cache': '0', 'gpu_external_free': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'device_id': '0'}}
find model: /home/jianming_ge/.insightface/models/buffalo_l/det_10g.onnx detection [1, 3, '?', '?'] 127.5 128.0
Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}, 'CUDAExecutionProvider': {'tunable_op_enabled': '0', 'cudnn_conv_use_max_workspace': '1', 'enable_cuda_graph': '0', 'do_copy_in_default_stream': '1', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv1d_pad_to_nc1d': '0', 'gpu_external_empty_cache': '0', 'gpu_external_free': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'device_id': '0'}}
model ignore: /home/jianming_ge/.insightface/models/buffalo_l/genderage.onnx genderage
Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}, 'CUDAExecutionProvider': {'tunable_op_enabled': '0', 'cudnn_conv_use_max_workspace': '1', 'enable_cuda_graph': '0', 'do_copy_in_default_stream': '1', 'arena_extend_strategy': 'kNextPowerOfTwo', 'cudnn_conv1d_pad_to_nc1d': '0', 'gpu_external_empty_cache': '0', 'gpu_external_free': '0', 'gpu_external_alloc': '0', 'gpu_mem_limit': '18446744073709551615', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'device_id': '0'}}
model ignore: /home/jianming_ge/.insightface/models/buffalo_l/w600k_r50.onnx recognition
set det-size: (640, 640)
faces:::: [{'bbox': array([105.29808,  83.55866, 218.93301, 230.41777], dtype=float32), 'kps': array([[137.7511 , 151.92409],
       [190.89203, 143.08504],
       [171.97752, 181.22136],
       [155.1662 , 205.49452],
       [192.61273, 197.9723 ]], dtype=float32), 'det_score': 0.8469027}]

人脸检测的效果:
在这里插入图片描述
文件目录树也贴上来供参考:
![在这里插入图片描述](https://img-blog.csdnimg.cn/591c2829601e4a4183c437125c8f569c.png在这里插入图片描述

1.3 人脸特征抽取

1.3.1 模型下载

https://github.com/deepinsight/insightface/tree/master/model_zoo
一般说来,模型越大,速度越慢,准确度越高
这个页面上的任何一个权重都可以用,我这里下载后重命名为recg.onnx
这是git 的样例,但其实是不全的。
新建bbb.py

"""
Call Recognition Models
"""
import cv2
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

handler = insightface.model_zoo.get_model('your_recognition_model.onnx')
handler.prepare(ctx_id=0)

刚开始运行肯定报错,因为你没有your_recognition_model.onnx 的权重,
通过代码追踪:它应该放在 ~/.insightface/models/your_recognition_model.onnx
在这里插入图片描述

1.3.2 重新跑一下检测和识别

而且权重应该放在项目目录下:
在这里插入图片描述
bbb.py 更新为:

"""
Call Recognition Models
"""
import cv2
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

app = FaceAnalysis(allowed_modules=['detection'],providers=['CUDAExecutionProvider', 'CPUExecutionProvider'],download=False)
app.prepare(ctx_id=0, det_size=(640, 640))
img = ins_get_image('ldh')  #不用带后缀,图片放到./insightface/python-package/insightface/data/images
faces = app.get(img)
print("faces::::", faces)

handler = insightface.model_zoo.get_model('w600k_r50.onnx')
handler.prepare(ctx_id=0)
img = ins_get_image('ldh')
feature = handler.get(img,faces[0])
print("size 0f feature:", len(feature))
print("feature:",feature)

注意点:实际在使用过程中,

  1. 先做人脸检测
  2. 做特征抽取
  3. 再做相似度计算

1.3.3 人脸监测返回值分析

人脸监测的返回值, 单张人脸:

faces:::: [{'bbox': array([398.00247,  76.93284, 517.12415, 217.21019], dtype=float32), 'kps': array([[420.43942, 127.73588],
       [472.40298, 119.96787],
       [440.8788 , 139.35797],
       [426.87814, 178.95143],
       [473.05652, 172.67671]], dtype=float32), 'det_score': 0.82732844}]

在这里插入图片描述

faces:::: [{'bbox': array([151.52905 ,   9.983715, 252.05127 , 149.92014 ], dtype=float32), 'kps': array([[179.53656 ,  65.759674],
       [225.35909 ,  66.749855],
       [202.66101 ,  89.19701 ],
       [176.11479 , 110.48839 ],
       [225.03027 , 111.73684 ]], dtype=float32), 'det_score': 0.903729}, {'bbox': array([390.146   ,  19.774494, 489.32114 , 154.33212 ], dtype=float32), 'kps': array([[417.48557 ,  73.57366 ],
       [463.98648 ,  72.462814],
       [442.4967  , 100.443985],
       [420.76508 , 118.47941 ],
       [463.62903 , 117.62505 ]], dtype=float32), 'det_score': 0.89457685}]
=============

在这里插入图片描述
返回一个list, len是人脸的数量
每个单元包含:
bbox 人脸框坐标
kps 人脸关键点的坐标 左眼、右眼、鼻子、嘴巴左侧、嘴巴右侧
det_score 检测的分数

人脸特征是返回一个512纬的向量:

size 0f feature: 512
feature: [-2.65807837e-01 -5.98709404e-01  1.44702032e-01  2.63355345e-01
  4.07146290e-02 -1.62199542e-01  2.32072305e-02 -2.41173565e-01
 -3.18579137e-01 -5.12303770e-01  4.71155867e-02  2.73445308e-01
 -8.21143925e-01  1.60933450e-01  2.68835127e-02 -1.19085282e-01
 -9.30740461e-02 -1.72320172e-01 -2.14248434e-01  2.86992230e-02
  3.17545533e-01  1.75784290e-01 -1.22256204e-01 -1.63961858e-01
 -8.66541564e-01  7.55451992e-02  2.67704695e-01 -5.87792039e-01
 -1.69785097e-02 -2.07043514e-02  5.06040215e-01  2.22781166e-01
 -2.63346657e-02  8.10962379e-01 -3.26032043e-01  1.26174808e-01
  3.17236811e-01  6.22351229e-01 -3.11159819e-01  4.34068412e-01
 -2.57273525e-01  2.18948558e-01  5.02837479e-01 -3.66360933e-01
 -4.49983001e-01  3.29971194e-01 -4.58328962e-01 -2.24694684e-01
 -6.20792098e-02 -2.27833763e-01 -2.73626387e-01 -1.57144777e-02
  7.91971147e-01  1.46265015e-01 -5.00584424e-01 -3.09522271e-01
  6.18827194e-02 -3.79446059e-01  4.31523114e-01 -4.84285116e-01
 -3.52546960e-01 -7.49332607e-02  6.07803948e-02  8.62523675e-01
 -4.10395920e-01 -2.44194195e-01 -3.41306150e-01 -8.33527073e-02
  5.68045788e-02 -1.97309047e-01  1.42464489e-01 -6.44236326e-01
  3.12686771e-01 -2.39409551e-01  4.39812720e-01 -4.36708421e-01
 -4.98010159e-01  1.31110698e-01 -5.03139734e-01 -4.52581614e-01
 -8.60964954e-02  1.03808708e-01 -3.57752778e-02  8.27392399e-01
  3.43307912e-01 -5.30499697e-01  2.62764663e-01  4.72977400e-01
  2.66696811e-01 -2.69342978e-02 -5.43406844e-01  3.88814628e-01
  8.32139477e-02 -7.24730372e-01  4.20132369e-01 -4.74645436e-01
 -1.48665071e-01  9.54597652e-01 -4.56728972e-02  3.51921208e-02
  3.72070462e-01 -1.53715964e-02 -8.53569135e-02 -8.37187350e-01
 -4.30278433e-03 -9.07578766e-02 -2.80029148e-01 -3.56460154e-01
 -6.20279536e-02  4.94443417e-01  1.15014195e+00 -4.20974493e-01
  4.80442680e-02 -4.37882274e-01 -1.71415120e-01 -3.32768500e-01
 -1.02889575e-01  2.16156662e-01  7.01144218e-01 -4.51926380e-01
 -4.58793879e-01  1.81827918e-02 -1.88612550e-01 -1.14988470e-02
 -1.77762285e-01 -2.05713645e-01  6.62348121e-02  1.67144701e-01
 -6.38863564e-01 -1.04559563e-01  2.81668335e-01  2.02162907e-01
 -7.78863609e-01  3.30200553e-01  5.50253451e-01  9.45175365e-02
  2.95698971e-01 -3.63492787e-01  3.95007521e-01  4.72791910e-01
 -1.13705151e-01  3.27019036e-01 -2.52318531e-01  5.03111146e-02
  7.85713866e-02 -4.40496325e-01 -1.02330513e-01 -2.04051405e-01
 -4.25574929e-01  1.15317412e-01 -2.48718798e-01  1.49252310e-01
  1.05377071e-01 -1.19814776e-01  5.92564166e-01  3.30846272e-02
  7.21025541e-02 -3.52899522e-01  7.61120737e-01 -6.52381837e-01
  6.50658727e-01 -5.15108407e-01 -1.94832787e-01 -4.66580153e-01
 -3.02693993e-01  3.60020995e-01 -6.04675889e-01  3.48266721e-01
  1.35741889e-01 -2.12851986e-01 -7.17316985e-01  1.31764725e-01
  2.28615105e-01  5.24750538e-02 -4.72336970e-02 -6.26476049e-01
 -4.56452340e-01  1.02681197e-01  3.58329445e-01 -3.19489807e-01
 -3.44365656e-01 -4.40581203e-01 -1.41268568e-02  6.94410443e-01
 -2.67537236e-01 -7.72025576e-03 -5.61997116e-01 -7.19041407e-01
  1.20449759e-01  6.45162582e-01  3.46629024e-01  1.10950135e-01
  8.20405841e-01  2.94094980e-01 -1.51019976e-01 -5.04539907e-02
 -7.21346065e-02  2.75275677e-01  4.68920708e-01 -5.11016130e-01
  1.87380016e-01  8.27821791e-02 -3.10316354e-01 -1.03935346e-01
  5.48591197e-01  9.24001709e-02 -3.89272362e-01 -1.15961254e+00
 -4.71911073e-01  3.22682679e-01 -3.27484250e-01 -2.13711888e-01
  8.46880302e-02  1.13394640e-01 -2.57271856e-01  4.57801521e-01
 -1.56833291e-01 -4.63344246e-01 -5.22429049e-02  1.63254842e-01
  3.00276607e-01  2.76694864e-01 -3.10461104e-01 -5.87711275e-01
 -1.89284272e-02  4.10056353e-01  6.57250285e-01 -8.84221718e-02
 -3.13798636e-01  5.00106215e-01 -4.48331796e-02 -5.13528764e-01
 -9.17405933e-02  7.00492561e-01 -2.52461191e-02 -4.65177923e-01
  3.35291862e-01  1.67592824e-01 -2.38635331e-01  6.97482347e-01
  1.63971394e-01 -3.29721011e-02 -1.26637876e-01  4.27806467e-01
 -5.34400046e-01 -2.61363145e-02  3.35392177e-01 -4.52100456e-01
 -1.15982279e-01 -4.80096698e-01 -1.20243188e-02 -8.81862491e-02
 -1.41368508e-01  8.21686313e-02  2.38767043e-01 -8.79521295e-02
  1.31764039e-01  9.93780792e-02  3.97302061e-01  2.62562603e-01
  5.31454384e-01  1.18952766e-01  1.63879409e-01  2.79800206e-01
  1.71809718e-01 -9.73480046e-02  5.50766960e-02  2.19342694e-01
  3.70924145e-01  2.22219989e-01 -1.48917332e-01  2.90967226e-01
 -1.31165534e-01 -1.25355244e-01  1.72034904e-01 -1.20657332e-01
  1.64537430e-01 -2.72813380e-01  4.12511617e-01  3.81849200e-01
 -3.10269538e-02 -5.84295869e-01 -1.62318975e-01  4.32897478e-01
 -2.25531310e-02  1.45282999e-01 -6.18601479e-02 -2.70079710e-02
  1.48326024e-01 -6.03496656e-02 -6.77019823e-03 -5.22333384e-01
 -1.42824680e-01  1.05511181e-01 -1.57965735e-01 -1.94174737e-01
  5.04310012e-01 -6.04734868e-02  3.38690877e-01  2.85632819e-01
  2.44570196e-01  4.41604286e-01 -2.50822127e-01 -3.39492172e-01
 -4.40223627e-02 -7.41581142e-01 -1.18939653e-01  1.32609561e-01
  5.79564087e-02 -1.12131372e-01 -3.30193996e-01  1.77734077e-01
 -8.44704509e-02  8.52265060e-02  7.22285330e-01 -7.39744082e-02
 -3.24919313e-01  1.52587101e-01  2.60848194e-01  4.75044131e-01
  8.96252871e-01 -7.45972931e-01 -1.91705048e-01 -5.63617408e-01
  4.07978743e-01 -5.42383134e-01  5.90304434e-01 -1.02651024e+00
  1.07888348e-01 -3.20087671e-02 -6.86910003e-02  4.59433228e-01
 -1.34848386e-01  1.79632828e-01 -6.78926706e-01  1.82937503e-01
 -6.39753282e-01 -2.47191161e-01 -1.42870158e-01 -3.90086859e-01
  2.62941182e-01 -5.99119365e-02 -9.82555468e-03 -2.31434792e-01
  4.23140265e-02 -2.33853012e-01  7.04509556e-01 -4.41635907e-01
 -2.51954973e-01 -3.28132778e-01  7.64646053e-01 -3.54267150e-01
  5.39237082e-01  1.79837737e-02  1.73653990e-01  1.45106345e-01
 -2.72235245e-01 -5.94357669e-01 -3.84668678e-01 -2.96734065e-01
  8.66554603e-02  5.53680919e-02 -7.88553357e-01  1.36896238e-01
 -4.14724737e-01 -1.44677877e-01  1.79900452e-01 -1.39882132e-01
  2.18250602e-01  6.80885389e-02 -7.68631250e-02 -7.89565086e-01
  3.48717213e-01  5.64985991e-01  5.58483787e-02 -8.17401558e-02
  2.03474388e-01 -1.07692860e-01  6.84533358e-01  3.19718868e-01
  1.21635854e-01  3.41574609e-01 -1.78951304e-02  2.78006196e-01
  1.80511326e-02 -6.24188110e-02 -6.32650331e-02  1.31553754e-01
  1.79080918e-01  1.01404369e-01  4.41990018e-01  9.36895087e-02
  7.87015259e-02  2.14785039e-01 -5.45855701e-01  2.24413946e-01
  4.32758123e-01 -4.15375143e-01  2.15920016e-01  2.70790398e-01
  6.58806413e-02  1.41609073e-01  3.54366191e-02 -3.72616023e-01
  3.92095059e-01 -9.02478099e-02  4.66177404e-01 -6.86050534e-01
 -3.16491425e-01  4.46931541e-01 -2.10206121e-01  6.28514409e-01
 -2.65414834e-01 -3.76454681e-01 -3.56145829e-01 -1.18043542e-01
  5.63065000e-02  6.98566914e-01 -3.88334543e-01  5.95293581e-01
  6.92259550e-01  2.15426758e-01  6.51695311e-01  1.98373515e-02
 -1.47576705e-01 -3.12872767e-01  4.05580014e-01  2.66416162e-01
  1.96047127e-01 -1.27053857e-01  1.09347150e-01  3.83434832e-01
  1.69589058e-01 -3.51539433e-01  2.03101888e-01  5.83723664e-01
 -5.45567989e-01  8.64841640e-02  1.94809675e-01 -2.73879915e-01
  5.09571843e-02  9.19594914e-02 -2.97315329e-01 -2.41457775e-01
  6.12340942e-02  1.42051131e-01  3.24435651e-01 -7.38600254e-01
 -4.35348183e-01  1.50280312e-01  2.81985532e-02  5.68533838e-01
  2.32664168e-01  3.33400816e-01  1.46391779e-01 -5.85084502e-03
 -1.55448794e-01 -4.67291296e-01 -4.34049487e-01 -3.40150416e-01
  1.04534440e-01 -4.27028328e-01  2.94970989e-01  3.17830712e-01
  5.78037322e-01 -2.43507465e-03  6.16211236e-01 -1.76521957e-01
 -1.05725817e-01 -2.66839921e-01  6.76848069e-02  2.33130768e-01
  3.24840128e-01  1.93292648e-01 -1.03790827e-01 -3.10859770e-01
  1.08004078e-01  4.30708565e-02 -1.50686622e-01 -3.32239121e-01
 -7.74850786e-01  8.22230577e-02 -2.64589787e-01 -1.18717141e-01
 -1.79947644e-01  2.60864738e-02  7.45431662e-01 -6.43727034e-02
 -1.80508792e-01 -5.09034805e-02 -1.89890876e-01  1.10911153e-01
  3.64015251e-01 -2.90384492e-07  4.50303376e-01  1.55005336e-01
 -4.08384293e-01  4.87070352e-01  1.31157666e-01 -1.15866172e+00
 -2.70245939e-01 -4.77115929e-01  8.44599679e-02  3.13389778e-01
 -3.81731451e-01  3.79520021e-02  4.61172126e-02  5.15780486e-02
  2.22334802e-01 -6.06625915e-01 -2.58048952e-01 -1.14576712e-01]

1.3.4 计算相似度

相似度计算就是用余弦函数进行计算,计算出相似度,其实就是识别的内容。

 # 计算相似度
 similarity = np.dot(feature1, feature2.T)

1.4 全流程的相似度

mmp 搞来搞去,这里有一个pipline

import argparse
import cv2
import sys
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

assert insightface.__version__>='0.3'

parser = argparse.ArgumentParser(description='insightface app test')
# general
parser.add_argument('--ctx', default=0, type=int, help='ctx id, <0 means using cpu')
parser.add_argument('--det-size', default=640, type=int, help='detection size')
args = parser.parse_args()

app = FaceAnalysis()
app.prepare(ctx_id=args.ctx, det_size=(args.det_size,args.det_size))

img = ins_get_image('t1')
faces = app.get(img)
assert len(faces)==6
rimg = app.draw_on(img, faces)
cv2.imwrite("./t1_output.jpg", rimg)

# then print all-to-all face similarity
feats = []
for face in faces:
    feats.append(face.normed_embedding)
feats = np.array(feats, dtype=np.float32)
sims = np.dot(feats, feats.T)
print(sims)

执行命令:python ccc.py --ctx 0 输出,分数是1的代表最相似

[[ 1.0000002   0.06442557 -0.01041015 -0.08265568  0.03555955 -0.02871545]
 [ 0.06442557  1.0000002   0.02620501  0.09680527 -0.02184767  0.21340981]
 [-0.01041015  0.02620501  0.99999994  0.14635125  0.06818002 -0.03542848]
 [-0.08265568  0.09680527  0.14635125  1.0000001  -0.0301404  -0.01418785]
 [ 0.03555955 -0.02184767  0.06818002 -0.0301404   0.99999994  0.05765504]
 [-0.02871545  0.21340981 -0.03542848 -0.01418785  0.05765504  0.99999964]]

在这里插入图片描述
6个人都比一遍,肯定对角线最相似啊,内部是不是已经做了人脸矫正和对齐,就不得而知了,懂的大神可以留言一下。
跑到这里,其实就差业务化了

2. 业务化人脸识别

敬请期待
-----分割线以上是20230529完成

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

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

相关文章

HTML+CSS实训——Day05——JavaScript基础知识点

前言 上一周我们只做了静态页面&#xff0c;这周开始要学js了&#xff0c;那我们先来认识一下他的语法和变量吧。 知识点 变量定义 学习了var还有console.log()输出变量 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8&…

点云配准算法综述-完整解读

点云配准的挑战 同源点云配准 同源点云的配准是指从同一类型的传感器,但在不同的时间或视角下获取的点云在进行配准问题中存在的挑战,其主要包含了 噪声和离群值。在不同的采集时间,环境和传感器噪声是不同的,采集到的点云在同一三维位置附近会包含噪声和异常值。部分重叠…

全网最火爆,从接口测试到接口自动化测试总结,卷王进阶高级...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 Python接口自动化测…

设计模式之美-为什么基于接口而非实现编程?有必要为每个类都定义接口吗?

我愿意称之为最强设计书籍之一。看完这篇文章使我对代码编写有了新的思考。值得注意的是文章全篇写的是伪代码&#xff0c;并没有真正实现方法的逻辑&#xff0c;不过这样反而有利于逻辑的理解。 在上一节课中&#xff0c;我们讲了接口和抽象类&#xff0c;以及各种编程语言是如…

如何跑通一个java项目

查找项目代码的途径&#xff1a;github,码云&#xff0c;掘金网 以小说精品屋项目(掘金网)为例&#xff1a; 先读Readme&#xff08;这里会介绍项目结构和技术选型&#xff09;&#xff0c;这里还会告诉你们怎么跑起来这个项目&#xff0c;比如让你先安装数据库&#xff0c;然…

从业者指南:专业编辑和校对技巧

在写作领域&#xff0c;编辑和校对是确保高质量作品的关键步骤。作为从业者&#xff0c;你需要掌握专业的编辑和校对技巧&#xff0c;以提高客户满意度和自己的市场竞争力。以下是一些值得关注的专业编辑和校对技巧。 1.建立良好的沟通 与客户保持良好的沟通是提高编辑和校对质…

如何更改 Linux 文件和目录权限?

在Linux系统中&#xff0c;文件和目录权限是安全性和访问控制的关键组成部分。正确设置文件和目录的权限可以确保只有授权的用户能够读取、写入或执行这些文件和目录。 本文将详细介绍如何在Linux系统中更改文件和目录的权限。 1. 文件和目录权限概述 在Linux系统中&#xff…

解决Kubernetes就绪检查导致网关不可用的问题

引言 在K8s环境中&#xff0c;由于就绪检查设置不合理的问题&#xff0c;导致出现网关不可用的情况。 本文将详细探讨这个问题的原因&#xff0c;并提供一些解决方案&#xff0c;帮助有需要的同学解决类似的问题。 注&#xff1a;网关使用 spring-cloud-gateway 问题描述 描…

记录两个Windows和Mac上部署阿里Canal无法启动的神坑

目录 一、问题列表 二、解决方案 三、参考资料 四、配置详解 五、数据库相关操作 一、问题列表 1、问题一&#xff1a;点击 startup.bat 窗口出现后立马闪退的问题。 2、问题二&#xff1a;启动后日志文件报错&#xff1a; ERROR com.alibaba.otter.canal.deployer.Cana…

办公OA系统性能分析案例

前言 信息中心老师反应&#xff0c;用户反馈办公系统有访问慢的情况&#xff0c;需要通过流量分析系统来了解系统的运行情况&#xff0c;此报告专门针对系统的性能数据做了分析。 信息中心已部署NetInside流量分析系统&#xff0c;使用流量分析系统提供实时和历史原始流量&am…

多项创新技术加持,实现零COGS的Microsoft Editor语法检查器

编者按&#xff1a;Microsoft Editor 是一款人工智能写作辅助工具&#xff0c;其中的语法检查器&#xff08;grammar checker&#xff09;功能不仅可以帮助不同水平、领域的用户在写作过程中检查语法错误&#xff0c;还可以对错误进行解释并给出正确的修改建议。神经语法检查器…

自动化测试框架的秘密,资深8年测试带你揭开,跟上测试“潮流“...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 Python自动化测试&…

携手共创开源新格局|2023开放原子全球开源峰会将于6月11日在京隆重开幕

6月11-13日&#xff0c;2023开放原子全球开源峰会将在全球数字经济大会期间召开。本次峰会将以“开源赋能&#xff0c;普惠未来”为主题&#xff0c;通过开幕式暨高峰论坛、分论坛、主题展览、开源活动周等多种形式&#xff0c;聚集政、产、学、研、用、创、投、金等各领域优势…

RPC学习笔记【一】:概述

文章目录 一、简介1.1 引言1.2 架构的演变过程 二、RPC 的设计2.1 设计目标2.2 核心问题01 通信方式02 协议03 序列化04 远程代理类 2.3 衍生方案 - 注册中心 一、简介 1.1 引言 RPC 是远程过程调用 &#xff08;Remote Procedure Call&#xff09;的缩写形式&#xff0c;是一…

一文搞懂Python时间序列预测(步骤,模板,python代码)

预测包括&#xff0c;数值拟合&#xff0c;线性回归&#xff0c;多元回归&#xff0c;时间序列&#xff0c;神经网络等等 对于单变量的时间序列预测&#xff1a;模型有AR,MA,ARMA,ARIMA&#xff0c;综合来说用ARIMA即可表示全部。 数据和代码链接&#xff1a;数据和Jupyter文…

ArcGIS10.8下载及安装教程(附安装步骤)

谷歌云&#xff1a; https://drive.google.com/drive/folders/10igu7ZSMaR0v0WD7-2W-7ADJGMUFc2ze?uspsharing ArcGIS10.8 百度网盘&#xff1a; https://pan.baidu.com/s/1s5bL3QsCP5sgcftCPxc88w 提取码&#xff1a;kw4j 阿里云&#xff1a; https://www.aliyundriv…

Linux—实操篇:远程登录到linux服务器

远程登录客户端工具有 Xshell7(远程登录)&#xff0c;Xftp7&#xff08;文件传输&#xff09;,这里介绍Xshell和Xftp&#xff0c;其他的远程工具大同小异 1、远程登录Linux—Xshell 介绍&#xff1a;Xshell是目前最好的远程登录到Linux的软件&#xff0c;流畅的速度并且完美解…

如何制作污水处理流程图?简单方式说明

污水处理是指对污水进行处理&#xff0c;以使其能够满足环境保护和人类生产生活用水的需要。污水处理流程图是整个污水处理过程的图解&#xff0c;能够直观地展现污水处理的步骤和流程。 有很多方式可以制作流程图&#xff0c;比如一些站点可以在线制作&#xff0c;还兼具了思维…

chatgpt赋能python:Python下载代码:探索更快、更简单的方式

Python下载代码&#xff1a;探索更快、更简单的方式 Python是一个功能强大的编程语言&#xff0c;可以用来开发各种应用程序&#xff0c;从Web应用程序到数据科学和机器学习。作为一个高级语言&#xff0c;它通常看起来更易于理解和编写&#xff0c;相比其他编程语言更容易维护…

现阶段检验检测认证行业到底是一个什么样的行业?

为企业创造不一样的价值&#xff01; TIC行业研究先行者、行业信息送水人&#xff01; 内容摘要 此文章重点讲述了现阶段检验检测认证行业到底是一个什么样的行业&#xff0c;以及分析这个行业好与不好的明显特点。 此文章重点分析了现阶段检验检测认证行业的驱动力、竞争格…