#在根目录下创建一个output目录
mkdir /output
cd /output/
#下载tensorflow object detec api 代码
git clone https://github.com/tensorflow/models.git
#安装依赖项
pip install Cython
pip install pillow
pip install lxml
pip install jupyter
pip install matplotlib
pip install opencv-python
pip install pycocotools
cd /output/models/research/
#编译
protoc object_detection/protos/*.proto --python_out=.
#安装
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
#验证
python object_detection/builders/model_builder_test.py
#下载图片及标注文件
cd /output
git clone https://github.com/sanfooh/tensorflow_object_detection_api_demo.git
我们还在下载一个预训练文件
#下载预训练文件
cd /output/tensorflow_object_detection_api_demo
wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2017_11_17.tar.gz
tar -xzvf ssd_mobilenet_v1_coco_2017_11_17.tar.gz
rm -r ssd_mobilenet_v1_coco_2017_11_17.tar.gz
生成tfrecord
#生成tfrecord数据集
python create_tf_record.py
生成之后,我们可以在winscp中看到如下的文件:
mkdir mytrain
python /output/models/research/object_detection/train.py --train_dir=mytrain/ --pipeline_config_path=net.config --logtostderr
cd /output/tensorflow_object_detection_api_demo
tensorboard --logdir=mytrain
cd /output/tensorflow_object_detection_api_demo
mkdir evalpython /output/models/research/object_detection/eval.py \
--logtostderr \
--pipeline_config_path=net.config \
--checkpoint_dir=mytrain/ \
--eval_dir=eval/
cd /output/tensorflow_object_detection_api_demo
tensorboard --logdir=eval
cd /output/tensorflow_object_detection_api_demo
python /output/models/research/object_detection/export_inference_graph.py \
--input_type image_tensor \
--pipeline_config_path /output/tensorflow_object_detection_api_demo/net.config \
--trained_checkpoint_prefix /output/tensorflow_object_detection_api_demo/mytrain/model.ckpt-35187 \
--output_directory /output/tensorflow_object_detection_api_demo/mymodel
#利用Flask来发布模型
pip install flask
pip install flask_wtf
#启动服务
python /output/tensorflow_object_detection_api_demo/web/app.py