Tensorflow框架下Faster-RCNN实践(二)——用自己制作的数据训练Faster-RCNN网络(附代码)

  1. 修改make.sh
#!/usr/bin/env bash
TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
echo $TF_INC

CUDA_PATH=/usr/local/cuda/

cd roi_pooling_layer

nvcc -std=c++11 -c -o roi_pooling_op.cu.o roi_pooling_op_gpu.cu.cc \
    -I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -arch=sm_52

## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
#g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o roi_pooling.so roi_pooling_op.cc \
#   roi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64

# for gcc5-built tf
#g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=1 -o roi_pooling.so roi_pooling_op.cc \
#   roi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64
g++ -std=c++11 -shared -o roi_pooling.so roi_pooling_op.cc  -D_GLIBCXX_USE_CXX11_ABI=0  \
    roi_pooling_op.cu.o -I $TF_INC  -D GOOGLE_CUDA=1 -fPIC $CXXFLAGS \
    -lcudart -L $CUDA_PATH/lib64 
cd ..


# add building psroi_pooling layer
cd psroi_pooling_layer
nvcc -std=c++11 -c -o psroi_pooling_op.cu.o psroi_pooling_op_gpu.cu.cc \
    -I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -arch=sm_52

g++ -std=c++11 -shared -o psroi_pooling.so psroi_pooling_op.cc -D_GLIBCXX_USE_CXX11_ABI=0  \
    psroi_pooling_op.cu.o -I $TF_INC -D GOOGLE_CUDA=1  -fPIC $CXXFLAGS \
        -lcudart -L $CUDA_PATH/lib64

## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
#g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o psroi_pooling.so psroi_pooling_op.cc \
#   psroi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64

cd ..
  1. –restore -0(位置)
python ./faster_rcnn/train_net.py --gpu 0 --weights ./data/pretrain_model/VGG_imagenet.npy --imdb voc_2007_trainval --iters 70000 --cfg ./experiments/cfgs/faster_rcnn_end2end.yml --network VGGnet_train --restore 0 --set EXP_DIR exp_dir 
  1. 修改run_profilling.sh
#!/bin/bash

python -m cProfile -o experiments/profiling/profile.out ./faster_rcnn/train_net.py\
 --gpu 0 --weights data/pretrain_model/VGG_imagenet.npy --imdb voc_2007_trainval \
 --iters 1000 --cfg experiments/cfgs/faster_rcnn_end2end.yml --network VGGnet_train

# generate an image
if [ ! -f experiments/profiling/gprof2dot.py ]; then 
    echo "Downloading ... "
    wget https://raw.githubusercontent.com/jrfonseca/gprof2dot/master/gprof2dot.py -O experiments/profiling/gprof2dot.py
fi
python experiments/profiling/gprof2dot.py -f pstats experiments/profiling/profile.out | dot -Tpng -o experiments/profiling/profile.png
#!/bin/bash

python -m cProfile -o experiments/profiling/profile.out ./faster_rcnn/train_net.py\
 --gpu 0 --weights data/pretrain_model/VGG_imagenet.npy --imdb voc_2007_trainval \
 --iters 1000 --restore 0 --cfg experiments/cfgs/faster_rcnn_end2end.yml --network VGGnet_train

# generate an image
if [ ! -f experiments/profiling/gprof2dot.py ]; then 
    echo "Downloading ... "
    wget https://raw.githubusercontent.com/jrfonseca/gprof2dot/master/gprof2dot.py -O experiments/profiling/gprof2dot.py
fi
python experiments/profiling/gprof2dot.py -f pstats experiments/profiling/profile.out | dot -Tpng -o experiments/profiling/profile.png
  1. 替换自己的数据 删除 cache/*.pkl
  2. cfgs NCLASSES 2
EXP_DIR: faster_rcnn_voc_vgg
LOG_DIR: faster_rcnn_voc_vgg
IS_MULTISCALE: False
NET_NAME: VGGnet
ANCHOR_SCALES: [8, 16, 32]
NCLASSES: 2 
TRAIN:
  OHEM: True
  RPN_BATCHSIZE: 2000
  BATCH_SIZE: 300
  LOG_IMAGE_ITERS: 100
  DISPLAY: 100
  SNAPSHOT_ITERS: 5000
  HAS_RPN: True
  LEARNING_RATE: 0.001
  MOMENTUM: 0.9
  GAMMA: 0.1
  STEPSIZE: 60000
  IMS_PER_BATCH: 1
  BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
  RPN_POSITIVE_OVERLAP: 0.7
  RPN_BATCHSIZE: 256
  PROPOSAL_METHOD: gt
  BG_THRESH_LO: 0.0
  PRECLUDE_HARD_SAMPLES: True
  BBOX_INSIDE_WEIGHTS: [1, 1, 1, 1]
  RPN_BBOX_INSIDE_WEIGHTS: [1, 1, 1, 1]
  RPN_POSITIVE_WEIGHT: -1.0
  FG_FRACTION: 0.3
  WEIGHT_DECAY: 0.0005
TEST:
  HAS_RPN: True
  1. 对自己的数据扩充pad
  2. sys.path.appent
  3. ckpt.index ckpt.meta ->ckpt
  4. 修改train.py (8.9 在一块)
In train.py: +from tensorflow.core.protobuf import saver_pb2
and in function of "def init": 
self.saver = tf.train.Saver(max_to_keep=100,write_version=saver_pb2.SaverDef.V1)

修改plt.show()的位置,并且保存生成的图片
11.运行test的时候,修改cfgs 默认参数,21->2

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值