1. 程式人生 > >Faster RCNN + Tensorflow 訓練自己的模型

Faster RCNN + Tensorflow 訓練自己的模型

1. 環境:Ubuntu16.04 + 1080顯示卡

2.所採用的程式:https://github.com/endernewton/tf-faster-rcnn

3. 資料集的更換

(1)tf-faster-rcnn/data下新增cache資料夾(空資料夾,不用放東西),imagenet_weights資料夾(存放預訓練模型VGG16.ckpt),VOCdevkit2007資料夾。

(2)VOCdevkit2007資料夾下:建立三個資料夾:

          annotations_cache;

         results—>VOC2010—>Main;

         VOC2007—>Annotations; ImageSets; JPEGImages

(3)Annotations下存放所有的標籤

        JPEGImages下存放所有的訓練測試圖片

         ImageSets 下建立Main資料夾,Main下存放 test.txt;  train.txt;  trainval.txt;  val.txt四個檔案(不能缺少)             

4. 修改程式

(1)lib/setup.py: 修改顯示卡資訊

(2)tools/demo.py:  class修改為自己的類別;下面TEST之後的數字21改為自己的類別數目+1

(3)lib/datasets/pascal_voc.py: 修改為自己的類別數目

5. Build the Cython modules

cd tf-faster-rcnn/lib
make clean
make
cd ..

6.Install the Python COCO API. The code requires the API to access COCO dataset

cd data
git clone https://github.com/pdollar/coco.git
cd coco/PythonAPI
make
cd ../../..

7.Train (and test, evaluation)

./experiments/scripts/train_faster_rcnn.sh [GPU_ID] [DATASET] [NET]
# GPU_ID is the GPU you want to test on
# NET in {vgg16, res50, res101, res152} is the network arch to use
# DATASET {pascal_voc, pascal_voc_0712, coco} is defined in train_faster_rcnn.sh
# Examples:
./experiments/scripts/train_faster_rcnn.sh 0 pascal_voc vgg16
./experiments/scripts/train_faster_rcnn.sh 1 coco res101

8.Visualization with Tensorboard

tensorboard --logdir=tensorboard/vgg16/voc_2007_trainval/ --port=7001 &
tensorboard --logdir=tensorboard/vgg16/coco_2014_train+coco_2014_valminusminival/ --port=7002 &

9.Test and evaluate

./experiments/scripts/test_faster_rcnn.sh [GPU_ID] [DATASET] [NET]
# GPU_ID is the GPU you want to test on
# NET in {vgg16, res50, res101, res152} is the network arch to use
# DATASET {pascal_voc, pascal_voc_0712, coco} is defined in test_faster_rcnn.sh
# Examples:
./experiments/scripts/test_faster_rcnn.sh 0 pascal_voc vgg16
./experiments/scripts/test_faster_rcnn.sh 1 coco res101

10. You can use tools/reval.sh for re-evaluation

#By default, trained networks are saved under:
output/[NET]/[DATASET]/default/

#Test outputs are saved under:
output/[NET]/[DATASET]/default/[SNAPSHOT]/

#Tensorboard information for train and validation is saved under:
tensorboard/[NET]/[DATASET]/default/
tensorboard/[NET]/[DATASET]/default_val/

參考:https://github.com/endernewton/tf-faster-rcnnREADME.md