【深度学习】Python快捷调用InsightFace人脸检测,纯ONNX推理

pypi资料:

https://pypi.org/project/insightface/

模型选择:

https://github.com/deepinsight/insightface/tree/master/python-package#model-zoo

onnxruntime的GPU对应CUDA :

https://onnxruntime.ai/docs/reference/compatibility

https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html

我的环境 CUDA 11.6 python3.8安装:

pip install insightface onnx==1.13 onnxruntime-gpu==1.14 -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
pip install opencv-python

GPU执行代码:


import cv2
import numpy as np
from insightface.app import FaceAnalysis

app = FaceAnalysis(name='buffalo_sc',
                   providers=['CUDAExecutionProvider'])  # 使用的检测模型名为buffalo_sc
app.prepare(ctx_id=0, det_size=(640, 640))  # ctx_id小于0表示用cpu预测,det_size表示resize后的图片分辨率

img = cv2.imread("sunyanzi.png")  # 读取图片
faces = app.get(img)  # 得到人脸信息
# print(faces)
for facedata in faces:
    print(facedata["bbox"].shape)  # 人脸框坐标
    print(facedata["kps"].shape)  # 人脸关键点坐标
    print(facedata["det_score"])  # 人脸检测分数
    print(facedata["embedding"].shape)  # 人脸特征向量


CPU执行代码:

import cv2
import numpy as np
from insightface.app import FaceAnalysis

app = FaceAnalysis(name='buffalo_sc',
                   providers=['CPUExecutionProvider'])  # 使用的检测模型名为buffalo_sc
app.prepare(ctx_id=-1, det_size=(640, 640))  # ctx_id小于0表示用cpu预测,det_size表示resize后的图片分辨率

img = cv2.imread("sunyanzi.png")  # 读取图片
faces = app.get(img)  # 得到人脸信息
# print(faces)
for facedata in faces:
    print(facedata["bbox"].shape)  # 人脸框坐标
    print(facedata["kps"].shape)  # 人脸关键点坐标
    print(facedata["det_score"])  # 人脸检测分数
    print(facedata["embedding"].shape)  # 人脸特征向量

只想要人脸检测推理咋整:

https://github.com/xddun/insightface_onnx_infer

你可能感兴趣的:(深度学习机器学习,深度学习,python,人工智能)