02 - Tensorflow Object Detection 环境快速安装及更新脚本

该脚本用于快速准备好 object detection 所需要的代码环境。

如脚本运行出错,则确保已安装 git, protobuf-compiler, make, python3 以及 python 下的 cython, matplotlib

更多说明请参考 https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md

quick_install_models.sh
#!/bin/bash
 
# Description: 快速更新至最新 tensorflow-models 代码
# Author: liujun
# Date: 2019-05-28
 
set -e
 
if [[ ! -d "./models" ]]; then
    # 如果未存在 models ,则先下载
    echo "== 01 == 未找到 models 目录,准备下载。"
    git clone https://github.com/tensorflow/models.git
    echo "== 02 == 下载 models 完毕。"
else
    # 还原并更新代码
    echo "== 01 == 还原并更新 models 代码开始。"
    cd models
    git reset --hard
    git clean -xdf
    git checkout master
    git pull
    cd ..
    echo "== 02 == 还原并更新 models 代码完毕。"
fi
 
# 如果未存在 cocoapi ,则先下载
if [[ ! -d "./cocoapi" ]]; then
    echo "== 03 == 未找到 cocoapi 目录,准备下载。"
    git clone https://github.com/cocodataset/cocoapi.git
    echo "== 04 == 下载 cocoapi 完毕。"
else
    # 还原并更新代码
    echo "== 03 == 还原并更新 cocoapi 代码开始。"
    cd cocoapi
    git reset --hard
    git clean -xdf
    git checkout master
    git pull
    cd ..
    echo "== 04 == 还原并更新 cocoapi 代码完毕。"
fi
 
# 编译 cocoapi 并拷贝到 models 中。
echo "== 05 == 准备编译 cocoapi 。"
cd ./cocoapi/PythonAPI
# make
python3 setup.py build_ext --inplace
rm -rf build
cd ../../
echo "== 06 == 编译 cocoapi 完毕。"
rm -rf ./models/research/pycocotools/
cp -a ./cocoapi/PythonAPI/pycocotools ./models/research/pycocotools
echo "== 07 == 已拷贝 cocoapi 至 models 中。"
 
# 编译 models object detection 。
echo "== 08 == 准备编译 object detection 。"
cd ./models/research
protoc ./object_detection/protos/*.proto --python_out=.
cd ../../
echo "== 09 == 编译 object detection 完毕。"