天天看點

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

為了避免不必要的麻煩,先說一下我的系統版本

Python 3.6 tensorflow 1.10 windows 7

object detection API安裝

object detection API 安裝參見官方的github: https://github.com/tensorflow/models/tree/master/research/object_detection

這裡需要特别強調一下,一定要檢查一下,下面的python的包都安裝了,方法很簡單,全部執行一遍

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

coco API安裝

windows下面不需要--user選項,Oxford-IIIT Pet 資料集使用coco metrix, 是以下面必須執行這個指令行:

  1. pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

在windows下面遇到utf-8編碼錯誤

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

如下修正:

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

C:\Program Files\Python\Python36\Lib\site-packages\pip\compat\_init_.py

79行改成gbk, utf-8替換為gbk, 不一定是是79行。再次執行即可成功安裝

建立訓練資料記錄tfrecord

下載下傳好Oxford-IIIT Pets Dataset資料集,解壓縮到這裡

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

然後執行下面的指令行:

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

訓練資料成功建立在指定目錄:先切換到指定目錄,完整的指令行執行

  1. D:\tensorflow\models\research>python objectdetection/datasettools/createpettfrecord.py --labelmappath=objectdetection/data/petlabelmap.pbtxt

  2. --datadir=D:/petdata --output-dir=D:\tensorflow\mytrain\data

  3. 還不會看這裡:

  4. https://github.com/tensorflow/models/blob/master/research/objectdetection/g3doc/preparing_inputs.md

遷移學習

這步成功以後,就可以開始執行真正的訓練啦,等等,别着急,我們是基于預訓練模型的遷移學習,是以還有幾件事情必須搞定,

下載下傳預訓練的tensorflow模型,我這裡下載下傳的是

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

http://download.tensorflow.org/models/objectdetection/ssdmobilenetv1coco201801_28.tar.gz

解壓縮到指定目錄,我的完整目錄結構如下:

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

其實有+加号的表示目錄檔案夾, - 表示檔案

labelmap file來自 D:\tensorflow\models\research\objectdetection\data\petlabelmap.pbtxt pipeline config file來自 D:\tensorflow\models\research\objectdetection\samples\configs\ssdmobilenetv1pets.config

直接copy過來,然後打開

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

開始修改,把所有【PATH_TO_BE_CONFIGURED】都改到正确路徑上來:

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

儲存好啦,然後直接執行訓練的指令行:

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

各個參數選項解釋如下:

--pipelineconfigpath

訓練時候配置目錄,所有關于訓練各種輸入路徑、參數模型、參數網絡配置,都在這個裡面。

--modeldir

訓練時候會寫檔案的目錄,訓練完成輸出的模型儲存目錄

--numtrainsteps

訓練多少個steps

--numeval_steps

多少個eval, 基本上兩者要相差10倍以上 steps : eval

--alsologtostderr

表示日志資訊

如果遇到這個錯誤

TypeError: can't pickle dictvalues objects

這樣修改,打開model_lib.py

D:\tensorflow\models\research\objectdetection

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

繼續訓練就會很OK

啟動tensorboard檢視訓練過程: CPU 太慢了,半天走一個step

tensorflow object detection API訓練公開資料集Oxford-IIIT Pets Dataset

原文釋出時間為:2018-08-27

本文作者:gloomyfish

本文來自雲栖社群合作夥伴“

OpenCV學堂

”,了解相關資訊可以關注“

”。