python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)

  • 1、人脸业务流程
    • 1、人脸检测(Face Detection)问题
    • 2、人脸对齐(Face Alignment)问题
    • 3、人脸属性(Face Attribute)问题
    • 4、人脸比对(Face Compare)问题
  • 2、人脸识别相关数据集
  • 3、人脸检测
    • 1、人脸检测需要解决的问题
    • 2、小人脸检测问题
    • 4、人脸目标检测算法
    • 5、TensorFlow+SSD环境搭建
      • 1、官网下载需要的项目
      • 2、安装基础包
      • 3、安装重要包protobuf与protoc这两个包的版本必须一致否则会报错
  • 4、人脸检测数据集

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第1张图片

1、人脸业务流程

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第2张图片

1、人脸检测(Face Detection)问题

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第3张图片

2、人脸对齐(Face Alignment)问题

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第4张图片

3、人脸属性(Face Attribute)问题

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第5张图片

4、人脸比对(Face Compare)问题

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第6张图片

2、人脸识别相关数据集

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第7张图片
python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第8张图片

3、人脸检测

1、人脸检测需要解决的问题

1、人脸可能出现在图像中的任何一个位置
2、人脸可能有不同的尺度
3、人脸在图像中可能有不同的视角和姿态
4、人脸可能部分被遮挡

2、小人脸检测问题

1、下采样倍率很大时,人脸区域基本消失
2、相比于感受野和anchor的尺寸来说,人脸的尺寸太小
3、anchor匹配策略(IOU小且变化敏感)
4、正负样本比例失衡

解决方案:

1、多尺度策略
2、调整优化anchor策略
3、在线的难例挖掘
3、IOU计算方式

4、人脸目标检测算法

使用SSD检测模型(后期使用效果更优的yolov5目标检测算法进行优化)
SSD作为人脸检测器的有点如下:

1、端到端的训练
2、直接回归目标类别和位置
3、不同尺度的特征图上进行预测

SSD网络模型结构:(以VGG16为特征提取网络)

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第9张图片
python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第10张图片
关于SSD详细的讲解,请参考我的另一篇博文
https://blog.csdn.net/guoqingru0311/article/details/130320681

5、TensorFlow+SSD环境搭建

TensorFlow-gpu版本为1.13.0
项目路径:
https://github.com/tensorflow/models/tree/r1.13.0/research/object_detection
安装教程:
https://github.com/tensorflow/models/blob/r1.13.0/research/object_detection/g3doc/installation.md

环境搭建:

1、官网下载需要的项目

https://github.com/tensorflow/models/tree/r1.13.0
python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第11张图片

2、安装基础包

pip install pillow lxml Cython jupyter matplotlib pandas opencv-python  --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装tensorflow-gpu版,此次项目使用的是1.13.0
pip install tensorflow-gpu==1.13.0 --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple

3、安装重要包protobuf与protoc这两个包的版本必须一致否则会报错

(1)安装protobuf

# 安装protobuf(Note:protobuf默认安装的是2.6.1版,安装时需要安装版本大于3)
pip install protobuf==3.15.0

(2)安装 protoc
与protobuf对应的版本是protoc-3.0.0-linux-x86_64.zip

先查看是否安装过protoc
1、首先查看本机的protoc的版本

protoc --version

2、本人机器在安装之前输出的是2.6.1版本的protoc,是通过如下的命令安装的:

sudo apt install protobuf-compiler

(如果已经安装可能会因为版本不匹配出现以下报错问题)
python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第12张图片
开始正儿八经的安装教程了哈::

# 1、下载对应版本的安装包文件
wget  https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip

# 2、解压压缩包
apt-get install unzip
unzip protoc-3.0.0-linux-x86_64.zip -d protoc-3.0.0-linux-x86_64 
# 3、将解压后的文件目录移动到/opt目录下,方便写入环境变量
mv protoc-3.0.0-linux-x86_64/ /opt
cd /opt/protoc-3.0.0-linux-x86_64/bin
chmod +x protoc #这一步很必要,否则执行的还是2.6.1版本的
export PATH=/opt/protoc-3.0.0-linux-x86_64/bin:$PATH   # 写入环境变量
source ~/.bashrc

在这里插入图片描述
Note:此处需要保证protobuf与protoc版本保持一致,否则会报以下错误
在这里插入图片描述
3、编译proto文件
在research文件下执行以下命令,如果object_detection/protos/文件夹中每个proto文件都生成了对应以.py格式的代码文件,就说明编译成功了。

# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第13张图片
(3)将安装Slim加入PYTHONPATH

#1、 安装slim包必须保证与tensorflow、object项目同版本,否则会报错
# 需要cd到 */research/slim 目录下,执行以下语句
python setup.py install 
#2、因为要用到slim,所以得将slim加入python使用的path才能正常运行。还是在research文件下,执行以下命令:
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第14张图片
(4)安装完成测试

python object_detection/builders/model_builder_test.py

python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第15张图片
截止到以上,环境搭建已经完成,步骤确实复杂~~~~

4、人脸检测数据集

WIDER FACE数据集
python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第16张图片
python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第17张图片
Passcal VOC数据格式
python+TensorFlow实现人脸识别智能小程序的项目(包含TensorFlow版本与Pytorch版本)(二)_第18张图片

你可能感兴趣的:(python,tensorflow,pytorch)