人脸的检测与识别,这方面的文章,我们前期的文章也有相关的介绍,主要涉及到MediaPipe Face Detection,以及基于openCV的人脸检测与识别,并且我们基于CNN卷积神经网络训练了自己的人脸识别模型。本期我们分享一个可以用于2D与3D人脸检测与识别的python库InsightFace。

InsightFace是一个用于2D和3D人脸分析的集成Python库。 InsightFace 有效地实现了各种最先进的人脸识别、人脸检测和人脸对齐算法,并针对训练和部署进行了优化。它支持一系列主干架构,包括 IResNet、RetinaNet、MobileFaceNet、InceptionResNet_v2 和 DenseNet。 除了模型之外,它还可以使用 MS1M、VGG2 和 CASIA-WebFace 等面部数据集。

https://github.com/deepinsight/insightfacePyTorch 1.6+ and/or MXNet=1.6-1.8, with Python 3.x.

打开网易新闻 查看精彩图片

使用insightface前,我们需要安装相应的第三方库,insightface主要基于pytorch,在运行本期代码前,确保自己的电脑上安装了pytorch,且版本大于1.6。然后我们还需要安装insightface。

pip install insightface

这里只需要使用pip进行安装即可,安装过程中,会自动安装相关的第三方库。

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/Collecting insightface Downloading insightface-0.7.3.tar.gz (439 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 439.5/439.5 kB 9.9 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... doneRequirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from insightface) (1.22.4)Collecting onnx (from insightface) Downloading onnx-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.6/14.6 MB 101.3 MB/s eta 0:00:00Building wheels for collected packages: insightface Building wheel for insightface (pyproject.toml) ... done Created wheel for insightface: filename=insightface-0.7.3-cp310-cp310-linux_x86_64.whl size=1054571 sha256=36da8226c173934e3336d6477a2cdab835fb8a173e585bed38277691b2c9a4fb Stored in directory: /root/.cache/pip/wheels/e3/d0/80/e3773fb8b6d1cca87ea1d33d9b1f20a223a6493c896da249b5Successfully built insightfaceInstalling collected packages: onnx, insightfaceSuccessfully installed insightface-0.7.3 onnx-1.14.0

安装完成后,会自动安装insightface与onnx,当然此模型还需要安装onnxruntime,若电脑中有GPU可以安装GPU版本,当然若只有CPU,可以直接安装onnxruntime。

打开网易新闻 查看精彩图片