tf-faster-rcnn GPU配置详细步骤

Environment

Ubuntu 16.04
NVIDIA GTX 1060
CUDA 9.0
CuDNN 7.1.4
python3

Installation

  • Install opencv, cython, easydict
pip install opencv
pip install cython
pip install easydict
  • Clone the repository
git clone https://github.com/endernewton/tf-faster-rcnn.git
  • Build the cython modules
cd tf-faster-rcnn/lib
vim Makefile
#line 2:python -> python3

make clean
make
cd ..
  • Install the Python COCO API
cd data
git clone https://github.com/pdollar/coco.git
cd coco/PythonAPI

vim Makefile
#line 2:python -> python3

make
cd ../..
  • Setup data(e.g: PASCAL VOC 2007)
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar

tar xvf VOCtrainval_06-Nov-2007.tar
tar xvf VOCtest_06-Nov-2007.tar
tar xvf VOCdevkit_08-Jun-2007.tar

#VOC basic structure
$VOCdevkit/                           # development kit
$VOCdevkit/VOCcode/                   # VOC utility code
$VOCdevkit/VOC2007                    # image sets, annotations, etc.

cd $FRCN_ROOT/data                    
ln -s $VOCdevkit VOCdevkit2007        #$VOCdevkit: VOCdevkit的目录位置
  • Download resnet101 for voc pretrained model on 07+12 dataset
baidu cloud : https://pan.baidu.com/s/1LXHHuyYRr0fetnhQtKBayw
tar xvf voc_0712_80k-110k.tgz
  • Create a folder and a soft link to use the pre-trained model
NET=res101
TRAIN_IMDB=voc_2007_trainval+voc_2012_trainval
mkdir -p output/${NET}/${TRAIN_IMDB}
cd output/${NET}/${TRAIN_IMDB}                    #模型放在这个目录下面

ln -s ../../../data/voc_2007_trainval+voc_2012_trainval ./default  #建立一个软链接
cd ../../..
  • Run the demo
GPU_ID=0
CUDA_VISIBLE_DEVICES=$GPU_ID 
python3 ./tools/demo.py                  


-------------------------------------------------------------------------------------------
#如果遇到错误No module named 'tkinter'
在相应的.py文件中import matplotlib.pyplot as plt之前加上
import matplotlib as mpl
mpl.use('Agg')

参考gpu服务器使用matplotlib错误:http://www.mamicode.com/info-detail-2190555.html
  • Modify the program before train & test
vim ./lib/datasets/voc_eval.py
#line 121: 'w' -> 'wb'
#line 105: cachefile = os.path.join(cachedir, '%s_annots.pkl' % imagesetfile   
改为
cachefile = os.path.join(cachedir, '%s_annots.pkl' % imagesetfile.split("/")[-1].split(".")[0])

vim ./experiments/scripts/train_faster_rcnn.sh
#line 22: ITERS=70000 改为 ITERS=2000            #自己设置跑的轮数
#line 62: python -> python3
#line 73: python -> python3

vim ./experiments/scripts/test_faster_rcnn.sh
#line 22: ITERS=70000 改为 ITERS=2000
#line 58: python -> python3
#line 67: python -> python3
  • Test with pretrained resnet101 model
rm data/VOCdevkit2007/VOC2007/ImageSets/Main/test.txt_annots.pkl
GPU_ID=0
./experiments/scripts/test_faster_rcnn.sh $GPU_ID pascal_voc_0712 res101
  • Result

 

  • Train your own model

1) Download pre-trained models and weights

#VGG16
mkdir -p data/imagenet_weights
cd data/imagenet_weights
wget -v http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz
tar -xzvf vgg_16_2016_08_28.tar.gz
mv vgg_16.ckpt vgg16.ckpt
cd ../..

#ResNet101
mkdir -p data/imagenet_weights
cd data/imagenet_weights
wget -v http://download.tensorflow.org/models/resnet_v1_101_2016_08_28.tar.gz
tar -xzvf resnet_v1_101_2016_08_28.tar.gz
mv resnet_v1_101.ckpt res101.ckpt
cd ../..

2) Train & Test

#Train
./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

#Test
./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

参考:https://github.com/endernewton/tf-faster-rcnn

 

 

 

 

 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值