前面剛寫完tensorflow1.15+ssd_mobilenet_v2的環境搭建,發現tensorflow2.0+早已經支援Tensorflow object detection API,是以肯定要與時俱進,下面就開始tensorflow2.0的環境搭建吧。
首先申明,以下搭建步驟采納同門師弟部落格,文末附上原文連結,但因人而異,還是些許步驟不同,在此做個人的環境搭建總結。
1.環境建立
conda create -n tf2 pip python=3.8
conda activate tf2 # 激活
2.安裝Tensorflow2.2
pip install --ignore-installed --upgrade tensorflow-gpu==2.2.0 -i https://pypi.douban.com/simple/
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
3.安裝CUDA和CuDnn
conda install cudatoolkit=10.1 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/
conda install cudnn=7.6.5 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/
4.Tensorflow object detection API
4.1 下載下傳源碼檔案
git clone https://github.com/tensorflow/models.git
或者:到上述網址下載下傳并解壓,筆者就是采用這種方式,因為git clone一直下載下傳不下來。
4.2Protobuf的安裝配置
在激活的環境中運作指令行
conda install -c anaconda protobuf
或者下最新的壓縮包,筆者這裡下的是:protoc-3.13.0-linux-x86_64,進行解壓
進入models/research/目錄下
/home/lianlirong/models-master/protoc-3.13.0-linux-x86_64/bin/protoc object_detection/protos/*.proto --python_out=.
運作結束後可檢視protos檔案内,是否新生成很多.python檔案
4.3 配置PYTHONPATH路徑
export PYTHONPATH=$PYTHON:./models-master/research/slim
5.COCO API的安裝
方法一:
pip install cpython pip install
git+https:// github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI
方法二:筆者的方法
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
make
make install
python setup.py install
cp -r ./cocoapi/PythonAPI/pycocotools ./models-master/research/ # 複制pycocotools到models-master/research/
6.Object detection api
cp object_detection/packages/tf2/setup.py .
python -m pip --default-timeout=200 install . # --default-timeout=200延長網絡的反應的時間,避免下載下傳中斷
若出現:

某一依賴項一直下載下傳不下來,則可以先中斷,單獨下載下傳這一部分:
pip install tensorflow==2.3.1 -i https://pypi.douban.com/simple # 利用豆瓣源下載下傳速度更快。
.
7.驗證配置結果
cd ./models-master/research
python object_detection/builders/model_builder_tf2_test.py
若出現如下結果則配置成功
就此環境搭建就好了!!!!
參考連結:
https://blog.csdn.net/l13022736018/article/details/108737082