1. 程式人生 > >(Tensorflow Object detection Api)安裝

(Tensorflow Object detection Api)安裝

可以選擇master分支

也可以選擇其他分支進行下載。之所以這麼說,是因為有大神給出了在TX2上加速ssd-mobilenet-v1的方法,但是隻支援在r1.5分支下的models,因為tensorflow models不斷更新,將一些網路節點的名字給變掉了,所以要注意一下。
現在的master分支中,object detection開始特定支援Google TPU訓練資料,之前的版本(起碼我在5.22號 git下來的程式碼)是沒有對TPU的指定支援的。

3、安裝COCO APi
這個API(官方連結)主要在模型的eval中要用到。這個後期再說。
ubuntu&mac下:

git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
make
cp -r pycocotools ./models/research/

其實就是在PythonAPI目錄下執行

python setup.py

python setup.py build
python setup.py install

這裡需要說明一下,在之前版本的object detection的安裝中,coco api是不必須安裝的,正如tensorflow自己的文件所寫的:

Download the cocoapi and copy the pycocotools subfolder to the tensorflow/models/research directory if you are interested in using COCO evaluation metrics. The default metrics are based on those used in Pascal VOC evaluation. To use the COCO object detection metrics add metrics_set: “coco_detection_metrics” to the eval_config message in the config file. To use the COCO instance segmentation metrics add metrics_set: “coco_mask_metrics” to the eval_config message in the config file.

那個時候,在object detection目錄中的evaluator.py中,是預設採用pascal_voc_detection_metrics. 但是,我觀察到現在改為了eval_util.py檔案,而這個檔案中預設的metric就是coco資料集的metric:

EVAL_DEFAULT_METRIC = ‘coco_detection_metrics’

所以,總的來說,現在必須安裝coco api了,除非你不用現在的分支,而是git 歷史分支,又或者你不對你的模型進行eval(當然,這是不科學的)。

4、編譯protobuf

Tensorflow Object Detection API使用Protobufs來配置模型和訓練引數。在使用框架之前,必須編譯Protobuf庫。這應該通過在models/目錄執行以下命令來完成:

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

5、設定python搜尋路徑

(1)永久性修改:
1)開啟終端,輸入

open ./bash_profile

2)將開啟的檔案的最後一行進行如下替換(記得把pwd換成models在自己的電腦中的檔案路徑)

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

3)再在終端執行如下程式碼

source ~/.bash_profile

(2)或者暫時性修改

set PYTHONPATH=pwd;pwd\research;pwd\research\slim

這裡的pwd是需要你自己修改為你自己電腦上的models的路徑的,不要直接複製

如果之後你還是遇到類似 No module named ‘object_detection’ 的問題,你可以嘗試:
在research 目錄下執行:

python setup.py build
python setup.py install

或者參考這裡的討論.

6、安裝完畢:測試一下

python object_detection / builders / model_builder_test.py

輸出OK表示設定完成。