# Tensorflow mobilenet+ssd 训练人脸数据集 widerface

#  Tensorflow mobilenet+ssd 训练人脸数据集 widerface

## materials

- face-detection-ssd-mobilenet\
(/home/shenhui/face-detection-ssd-mobilenet)
IP:192.168.1.187
code:bmi123

-  object-detection
(/home/shenhui/shenhui/models/research/object-detection)
谷歌tensorflow api

- widerface data
it has been downloaded in the file: face-detection-ssd-mobilenet

## 步骤

### tensorflow环境搭建

pip install tensorflow-gpu

### tensorflow API的安装

sudo apt-get install protobuf-compiler python-pil python-lxml python-tk


sudo pip install Cython

sudo pip install jupyter

sudo pip install matplotlib

git clone https://github.com/cocodataset/cocoapi.git

cd cocoapi/PythonAPI

make

cp -r pycocotools /models/research/

- From tensorflow/models/research/

protoc object_detection/protos/*.proto --python_out=.



- From tensorflow/models/research/

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim


- 检验tensorflow API是否正确安装

python object_detection/builders/model_builder_test.py

###  将数据集转为TF-Record格式

- 将数据转化为Tf-Record格式,转到face-detection-ssd-mobilenet路径下运行

python 2_data_to_pascal_xml.py

python 3_xml_to_csv.py

python 4_generate_tfrecord.py --images_path=data/tf_wider_train/images --csv_input=data/tf_wider_train/train.csv --output_path=data/train.record

python 4_generate_tfrecord.py --images_path=data/tf_wider_val/images --csv_input=data/tf_wider_val/val.csv --output_path=data/val.record

### 修改config文件

- face-detection-ssd-mobilenet文件下的ssd_mobilenet_v1_face.config(%注:如果要修改模型,可以选择别的config文件)

- 主要的修改内容是:
- - 批量:batch size
- - 预训练模型:

fine_tune_checkpoint: "/Users/miaozou/Documents/projects/face-detection-ssd-mobilenet/data/ssd_mobilenet_v1_coco_11_06_2017/model.ckpt"
from_detection_checkpoint: true
- - 学习率等:

initial_learning_rate: 0.004
          decay_steps: 800720
decay_factor: 0.95

- - 相应的由1.2.3步骤中生成的train.record/val.record路径和face-detection-ssd-mobilenet中的face_label.pbtxt路径:
 
input_path: "/Users/miaozou/Documents/projects/face-detection-ssd-mobilenet/data/train.record"
  }
  
label_map_path: "/Users/miaozou/Documents/projects/face-detection-ssd-mobilenet/face_label.pbtxt"
}

input_path: "/Users/miaozou/Documents/projects/face-detection-ssd-mobilenet/data/val.record"
  }
  
label_map_path: "/Users/miaozou/Documents/projects/face-detection-ssd-mobilenet/face_label.pbtxt"

### 训练

- 转到 tensorflow/models/research/object-detection/0运行:

python /Users/miaozou/Documents/projects/models/research/object_detection/train.py --logtostderr --pipeline_config_path=ssd_mobilenet_v1_face.config --train_dir=checkpoints_dir

其中,train.py在下载的models/research/object-detection路径下,要根据自己的object-detection路径进行改变
pipeline_config_path是相应的config文件路径,这里是ssd_mobilenet_v1_face.config的路径
train_dir是生成的训练文件存放路径,需要自己新建,在这里我们在face-detection-ssd-mobilenet中新建New_train作为训练存放路径

### 输出模型(.pb文件)

python /Users/miaozou/Documents/projects/models/research/object_detection/export_inference_graph.py --input_type image_tensor --pipeline_config_path ssd_mobilenet_v1_face.config --trained_checkpoint_prefix checkpoints_dir/model.ckpt-200 --output_directory output_model/

其中,需要修改--trained_checkpoint_prefix checkpoints_dir/model.ckpt-200 --output_directory output_model/
将trained_checkpoints_prefix 的路径改成你的New_trian中的相应生成的model.ckpt-最大数字

         

你可能感兴趣的:(# Tensorflow mobilenet+ssd 训练人脸数据集 widerface)