安装cpython,python-opencv easydict
pip install cpython
pip install easydict
apt-get install python-opencv
进如 py-faster-rcnn/lib 进行make操作
make
进入 py-faster-rcnn/caffe-fast-rcnn
cp Makefile.config.example Makefile.config
对Makefile.config文件进行配置,我的配置文件如下:
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr# CUDA architecture setting: going with all of them.
# For CUDA <6.0, comment the *_50 lines for compatibility.
CUDA_ARCH :&#61; -gencode arch&#61;compute_20,code&#61;sm_20 \-gencode arch&#61;compute_20,code&#61;sm_21 \-gencode arch&#61;compute_30,code&#61;sm_30 \-gencode arch&#61;compute_35,code&#61;sm_35 \-gencode arch&#61;compute_50,code&#61;sm_50 \-gencode arch&#61;compute_50,code&#61;compute_50# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS :&#61; atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE :&#61; /path/to/your/blas
# BLAS_LIB :&#61; /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE :&#61; $(shell brew --prefix openblas)/include
# BLAS_LIB :&#61; $(shell brew --prefix openblas)/lib# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR :&#61; /usr/local
# MATLAB_DIR :&#61; /Applications/MATLAB_R2012b.app# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE :&#61; /usr/include/python2.7 \/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it&#39;s in root.
# ANACONDA_HOME :&#61; $(HOME)/anaconda
# PYTHON_INCLUDE :&#61; $(ANACONDA_HOME)/include \# $(ANACONDA_HOME)/include/python2.7 \# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES :&#61; boost_python3 python3.5m
# PYTHON_INCLUDE :&#61; /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB :&#61; /usr/lib
# PYTHON_LIB :&#61; $(ANACONDA_HOME)/lib# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE &#43;&#61; $(dir $(shell python -c &#39;import numpy.core; print(numpy.core.__file__)&#39;))/include
# PYTHON_LIB &#43;&#61; $(shell brew --prefix numpy)/lib# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER :&#61; 1# Whatever else you find you need goes here.
INCLUDE_DIRS :&#61; $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS :&#61; $(PYTHON_LIB) /usr/local/lib /usr/lib# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS &#43;&#61; $(shell brew --prefix)/include
# LIBRARY_DIRS &#43;&#61; $(shell brew --prefix)/lib# Uncomment to use &#96;pkg-config&#96; to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG :&#61; 1BUILD_DIR :&#61; build
DISTRIBUTE_DIR :&#61; distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG :&#61; 1# The ID of the GPU that &#39;make runtest&#39; will use to run unit tests.
TEST_GPUID :&#61; 0# enable pretty build (comment to see full commands)
Q ?&#61; &#64;
配置完Makefile.config文件后&#xff0c;执行&#xff1a;
make -j4
make pycaffe
目标检测数据集制作工具 labelImg https://blog.csdn.net/caicaiatnbu/article/details/85125018
修改 ../py-faster-rcnn/data/VOCdevkit2007/VOC2007/ 目录下的 Annotations 和 JPEGImage 以及ImageSets/Main 三个文件夹&#xff0c;下面依次讲述这个三个文件夹
JPEGImage 文件夹保存着所有图片&#xff0c;这里我们所有图片的格式统一都是jpg&#xff0c;命名规则"000001.jpg"开始。
Annotation 文件夹保存着每张图片对应的XML文件&#xff0c;这里我们将我们的XML文件格式贴出来&#xff1a;
ImageSets/Main 文件夹下包含4个.txt文件&#xff0c;分别为 train.txt val.txt trainval.txt test.txt &#xff0c;没给txt中保存都是图片的名称。
注意&#xff1a;trainval.txt 为 train.txt 和 val.txt的总和。train.txt 和 val.txt 里面保存的样本数一定要为偶数&#xff0c;否则会报错
修改 py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rcnn_train.pt 和 stage2_fast_rcnn_train.pt 两个文件
name: "ZF"
layer {name: &#39;data&#39;type: &#39;Python&#39;top: &#39;data&#39;top: &#39;rois&#39;top: &#39;labels&#39;top: &#39;bbox_targets&#39;top: &#39;bbox_inside_weights&#39;top: &#39;bbox_outside_weights&#39;python_param {module: &#39;roi_data_layer.layer&#39;layer: &#39;RoIDataLayer&#39;param_str: "&#39;num_classes&#39;: 6" #按训练集类更改&#xff0c;该值为类别数&#43;1}
}layer {name: "cls_score"type: "InnerProduct"bottom: "fc7"top: "cls_score"param { lr_mult: 1.0 }param { lr_mult: 2.0 }inner_product_param {num_output: 6 #按训练集类更改&#xff0c;该值为类别数&#43;1weight_filler {type: "gaussian"std: 0.01}bias_filler {type: "constant"value: 0}}
}layer {name: "bbox_pred"type: "InnerProduct"bottom: "fc7"top: "bbox_pred"param { lr_mult: 1.0 }param { lr_mult: 2.0 }inner_product_param {num_output: 24 #按训练集类更改&#xff0c;该值为&#xff08;类别数&#43;1&#xff09;* 4weight_filler {type: "gaussian"std: 0.001}bias_filler {type: "constant"value: 0}}
}
修改 py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rpn_train.pt 和 stage2_rpn_train.pt
name: "ZF"
layer {name: &#39;input-data&#39;type: &#39;Python&#39;top: &#39;data&#39;top: &#39;im_info&#39;top: &#39;gt_boxes&#39;python_param {module: &#39;roi_data_layer.layer&#39;layer: &#39;RoIDataLayer&#39;param_str: "&#39;num_classes&#39;: 6" #按训练集类更改&#xff0c;该值为类别数&#43;1}
}
修改py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/faster_rcnn_test.pt
layer {name: "cls_score"type: "InnerProduct"bottom: "fc7"top: "cls_score"inner_product_param {num_output: 6 #按训练集类更改&#xff0c;该值为类别数&#43;1}
}
layer {name: "bbox_pred"type: "InnerProduct"bottom: "fc7"top: "bbox_pred"inner_product_param {num_output: 24 #按训练集类更改&#xff0c;该值为&#xff08;类别数&#43;1&#xff09;* 4}
}
修改 py-faster-rcnn/lib/datasets/pascal_voc.py
注意 标签名尽可能为英文小写。否则会报bug
self._classes &#61; (&#39;__background__&#39;, # always index 0&#39;label_a&#39;,&#39;label_b&#39;,&#39;label_c&#39;,&#39;label_d&#39;,&#39;label_e&#39;)# &#39;aeroplane&#39;, &#39;bicycle&#39;, &#39;bird&#39;, &#39;boat&#39;,# &#39;bottle&#39;, &#39;bus&#39;, &#39;car&#39;, &#39;cat&#39;, &#39;chair&#39;,# &#39;cow&#39;, &#39;diningtable&#39;, &#39;dog&#39;, &#39;horse&#39;,# &#39;motorbike&#39;, &#39;person&#39;, &#39;pottedplant&#39;,# &#39;sheep&#39;, &#39;sofa&#39;, &#39;train&#39;, &#39;tvmonitor&#39;)
修改 py-faster-rcnn/lib/datasets/imdb.py
def append_flipped_images(self):num_images &#61; self.num_images#widths &#61; self._get_widths()widths &#61; [PIL.Image.open(self.image_path_at(i)).size[0]for i in xrange(self.num_images)]for i in xrange(num_images):boxes &#61; self.roidb[i][&#39;boxes&#39;].copy()oldx1 &#61; boxes[:, 0].copy()oldx2 &#61; boxes[:, 2].copy()boxes[:, 0] &#61; widths[i] - oldx2 - 1boxes[:, 2] &#61; widths[i] - oldx1 - 1for b in range(len(boxes)):if boxes[b][2]
删除缓存文件
删除 py-faster-rcnn文件夹下所有的.pyc 文件 以及 data文件件下的cache文件夹&#xff0c;
删除 data/VOCdevkit2007/annotations_cache 文件夹
删除 py-faster-rcnn/lib/datasets/ 下的imdb.pyc 和 pascal_voc.pyc
开始训练&#xff1a;
./experiments/scripts/faster_rcnn_alt_opt.sh 0 ZF pascal_voc