最近又需要做目标检测的任务,考虑到简单实用,我们实用tensorflow 官方的模型,记录一下在liunx的安装步骤
1、下载源码 git clone https://github.com/tensorflow/models.git
2、python3环境下,安装各种依赖包,
pip install tensorflow-gpu==1.12 #使用新版
pip install Cython
pip install contextlib2
pip install pillow
pip install lxml
pip install jupyter
pip install matplotlib
3、配置protobuf
在 /home/models/research/目录下:
protoc object_detection/protos/*.proto --python_out=.
但是如果出现以下报错:
object_detection/protos/calibration.proto:34:3: Expected "required", "optional", or "repeated".
则参考https://github.com/tensorflow/models/issues/1834#issuecomment-332531392
#You need to download protoc version 3.3 (already compiled). Use the protoc executable inside bin directory to run the commands like this:
tensorflow$ mkdir protoc_3.3
tensorflow$ cd protoc_3.3
tensorflow/protoc_3.3$ wget wget https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ chmod 775 protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ unzip protoc-3.3.0-linux-x86_64.zip
tensorflow/protoc_3.3$ cd ../models/research/
tensorflow/models/research$ /home/saikishor/tensorflow/protoc_3.3/bin/protoc object_detection/protos/*.proto --python_out=.
4、添加环境变量
export PYTHONPATH=$PYTHONPATH:/home/models/research:/home/models/research/slim
5、对相关文件进行配置
在 /home/models/research/目录下:
python setup.py build
python setup.py install
6、拷贝net文件夹
由于测试文件需要net文件中的文件,但是我加入环境变量还是报错
from nets.nasnet import pnasnet
ImportError: cannot import name 'pnasnet'
所以在 models/research/slim 目录下:
cp -r nets ../ #把nets文件夹拷贝到上一层
cd ..
7、测试是否可以执行:
#在 /home/models/research/目录下:
python object_detection/builders/model_builder_test.py