简介
InsightFace是一个基于深度学习的开源人脸识别项目,由蚂蚁金服的深度学习团队开发。该项目提供了人脸检测、人脸特征提取、人脸识别等功能,支持多种操作系统和深度学习框架。本文将详细介绍如何在Ubuntu系统上安装和实战InsightFace项目。
目前github有非常多的人脸识别开源项目,下面列出几个常用的开源项目:
- deepface
- compreface 是免费开源的人脸识别服务,无需事先掌握机器学习知识即可轻松集成到任何系统中。它提供了用于人脸识别、人脸验证、人脸检测、特征点检测、口罩检测、头部姿态检测、年龄和性别识别的REST API,并可通过Docker轻松部署。
- face_recognition 使用全球最简单的人脸识别库,从Python或命令行识别和操作人脸。
该库基于dlib构建,利用深度学习技术实现先进的面部识别功能。在Labeled Faces in the Wild基准测试中,模型的准确率高达99.38%。
此外,还提供了一个简单的face_recognition命令行工具,可以从命令行对一整套图像进行人脸识别! - facenet 使用TensorFlow实现的人脸识别
- facenet-pytorch 使用pytorch实现的人脸识别
- insightface
安装步骤
在开始之前,请确保您的Ubuntu系统满足以下要求:
- 操作系统:Ubuntu 16.04/18.04/20.04
- Python版本:Python 3.5及以上
- 深度学习框架:PyTorch或TensorFlow
- 其他依赖库:OpenCV、NumPy、Pillow等
安装依赖库
首先,安装Python和pip:
sudo apt update
sudo apt install python3 python3-pip python3-dev
在这一定要安装python3-dev,否则在构建insightface工程时会报错:
下面报错解决方法
mesh_core_cython.cpp:4:10: fatal error: Python.h: 没有那个文件或目录
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
然后,安装必要的依赖库:
pip3 install torch torchvision torchaudio nvidia-cudnn-cu12 numpy pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
最后,安装项目依赖库:
pip3 install opencv-python onnx tqdm scikit-image albumentations matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
下载InsightFace项目源码
# github clone
git clone https://github.com/deepinsight/insightface.git
# or gitee clone mirror
git clone https://gitee.com/mirrors/InsightFace.git
cd insightface
# 安装项目指定必要的依赖
pip3 install -r requirements.txt
工程文件介绍
下面是insightface工程主要目录,对于应用来讲主要使用标红框的目录。
构建python-package
python-package/cpp-package 主要是对insightface核心框架的应用封装,在开发应用时可以直接进行模块导入。
在执行测试demo前需要先执行该目录中的setup.py进行构建当前平台的部署。如果你是通过pip3直接安装的insightface模块’pip3 install insightface’,就无需执行。
执行如下:
cd python-package
python3 setup.py build_ext -i
如下图代表构建成功:
examples例程测试
因为我们是工程项目进行本地部署,所以我们需要将examples目录中的demo文件赋值到python-package目录中在执行,否则会提示无法正确导入insightface模块。
在首次执行demo的时候会自动进行模型下载,如果下载很慢的话也可以将模型先下载完后放到: ~/.insightface/models/目录下即可,默认下载的是buffalo_l模型
~/work/deep-study/insightface/insightface/python-package$ cp ../examples/demo_analysis.py ./
#执行demo
~/work/deep-study/insightface/insightface/python-package$ python3 demo_analysis.py
/home/djzheng/.local/lib/python3.8/site-packages/albumentations/__init__.py:13: UserWarning: A new version of Albumentations is available: 2.0.5 (you have 1.4.18). Upgrade us