目標物檢測_tensorflow_object_dection


一、背景介紹

1. 應用場景

a. 計數: 統計人,車,花甚至是微生物數量,在大部分基於圖像的系統中都要使用,尤其廣泛應用於監控視頻設備系統

b. 視覺搜索引擎:目標檢測作為索引圖像內容的處理流程之一。比如,你可以在不同的背景下找到某個特定的錢包

c. 空中影像分析:應用無人機攝像對人難以到達的地方進行自動監測(例如BetterView)或者使用物體檢測方法進行整體分析(例如TensorFlight)

2. 深度學習模型進階流程

a. overfit:

b.RCNN

c. fast-RCNN

d.YOLO

e.faster-RCNN

f.SSD 

g.R-FCN

3. 數據集

a. ImageNet

b. COCO

c. Pascal VOC

d.Oxford-IIIT Pet

e.KITTI Vision

二、模型版本

https://github.com/tensorflow/models/tree/266c7b87251dac41e977f3167f39078954f609dd/research/object_detection

三、走通版本3 (tensorflow 官網)

3.1 安裝環境

a. 下載代碼

git clone https://github.com/tensorflow/models.git

b. 安裝

sudo apt-get install protobuf-compiler python-pil python-lxml

sudo pip install jupyter

sudo pip install matplotlib

c. 配置環境

# From tensorflow/models/research/

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

# From tensorflow/models/research/

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

每次打開命令框需要重新輸入export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

#######################################################################################

配置路徑,開機啟動,自動遍歷此文件的指令
1>. home/coolpad/.bashr最下方增加:
export PYTHONPATH=$PYTHONPATH:/home/coolpad/models/research:/home/coolpad/models/research/slim
2>. 開機重啟生效,不重啟則需要在命令框運行source /home/coolpad/.bashrc

########################################################################################

d.查看是否配置成功

python object_detection/builders/model_builder_test.py

成功則出現:Ran 11 tests in 0.026s OK

3.2 使用API訓練模型

利用 TF Object Detection API 用COCO-pretrained Faster R-CNN with Resnet-101 model 預訓練遷移訓練一個 Faster RCNN 目標檢測模型,使用faster_rcnn_resnet101網絡訓練 Oxford-IIIT 寵物數據集

a. 下載訓練集

下載圖片:wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz     

解壓圖片:tar -xvf images.tar.gz

下載標注文件:wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz

解壓標注文件:tar -xvf annotations.tar.gz

b.轉tfrecord

python object_detection/create_pet_tf_record.py \

--label_map_path=object_detection/data/pet_label_map.pbtxt \

--data_dir=`pwd` \

 --output_dir=`pwd`

c. 下載預訓練的權重

wget http://storage.googleapis.com/download.tensorflow.org/models/object_detection/faster_rcnn_resnet101_coco_11_06_2017.tar.gz

tar -xvf faster_rcnn_resnet101_coco_11_06_2017.tar.gz

e. 建立訓練文件夾

在任何路徑mkdir my_train

將轉換的pet_train.record、pet_val.record復制到此文件夾

將object_detection/data/pet_label_map.pbtxt復制到此文件夾

object_detection/samples/configs/faster_rcnn_resnet101_pets.config復制到此文件夾

f. 修改faster_rcnn_resnet101_pets.config代碼路徑

將所有的PATH_TO_BE_CONFIGURED替換為my_train 的路徑

將fine_tune_checkpoint: "×××××××" 的×××××替換成下載的預訓練權重的路徑

g.運行訓練

cd /root/myfloder/models/research python3 object_detection/train.py \

--logtostderr \ --pipeline_config_path='./my_train/faster_rcnn_resnet152_pets.config' \

--train_dir='./my_train'

#####################################################################

從頭開始訓練模型:

將  fine_tune_checkpoint: "20170820/model.ckpt"

from_detection_checkpoint: true 改成false

#####################################################################

3.4 查看訓練數據:

tensorboard --logdir='./20180210'

3.5 評估訓練好的網絡

python3 object_detection/eval.py\

--logtostderr \ --pipeline_config_path='./my_train/faster_rcnn_resnet152_pets.config' \

--checkpoint_dir='./my_train/' \

--eval_dir='./my_train/'

以上的步驟已經走通遷移訓練

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM