ubuntu/debian

推荐列表 站点导航

当前位置:首页 > 操作系统 > ubuntu/debian >

Ubuntu16.04配置py-faster-rcnn

来源:网络整理  作者:网友投稿  发布时间:2020-12-27 12:15
说明 本来用的Ubuntu14.04,毕竟都说14比16稳定嘛。但是配置好了后,运行demo.py都没问题了,但是训练的时候出现 Type...

本来用的Ubuntu14.04,毕竟都说14比16稳定嘛。但是配置好了后,运行demo.py都没问题了,但是训练的时候出现 

TypeError numpy.float64 object cannot be interpreted as an index

都说是numpy版本问题,得用1.11.0,因此降到1.11.0(sudo pip install -U numpy==1.11.0)

但是装了numpy1.11.0后出现

numpy.core.multiarray failed to import 

网上都说版本不兼容,得升级到新版本。升级又出现上面那个问题。

我就无语了,上面两个是循环的问题啊,无法解决。

卡了好几天,最后通过apt-cache show python-numpy,查看到numpy版本居然是1.8!无论怎么更新,就算通过

import numpy

numpy.__version__

显示的都不是1.8。但其实内核是1.8,因为Ubuntu14只能支持到1.8,所以放弃了Ubuntu14

 

一、必要配置安装

CUDA、opencv我的其他文章已经写过了,也可参考网上其他教程,这里就跳过。

 

二、安装一些包

pip install cython

pip install easydict

apt-get install python-opencv

还有些包根据错误提示安装就好了。

 

三、下载py-faster-rcnn

使用git clone,保证caffe分支一起clone下来

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

 

四、进入py-faster-rcnn/lib

make

 

五、进入py-faster-rcnn\caffe-fast-rcnn

cp Makefile.config.example Makefile.config

然后配置Makefile.config:是否用CUDNN、是否是opencv3

重要的一点是必须

WITH_PYTHON_LAYER :=1

配置好后,执行:

make -j8 && make pycaffe

 

六、下载VOC2007数据集

(当然也可以直接用自己的数据集)

百度网盘下载VOC2007:

把VOC2007数据集放在py-faster-rcnn\data目录下,用自己的数据集替换VOC2007数据集。(替换py-faster-rcnn\data\VOCdevkit2007\VOC2007目录下的Annotations,ImageSets和JPEGImages)

 

六、下载ImageNet数据集下预训练得到的模型参数(用来初始化训练参数)

百度网盘下载地址:

解压后将该文件放在py-faster-rcnn\data下

 

七、训练参数修改(以ZF网络为例)

1、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_fast_rcnn_train.pt

代码一

layer {

name: 'data'

type: 'Python'

top: 'data'

top: 'rois'

top: 'labels'

top: 'bbox_targets'

top: 'bbox_inside_weights'

top: 'bbox_outside_weights'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+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: 16 #按训练集类别改,该值为类别数+1

weight_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: 64 #按训练集类别改,该值为(类别数+1)*4

weight_filler {

type: "gaussian"

std: 0.001

}

bias_filler {

type: "constant"

value: 0

}

}

}

2、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rpn_train.pt

layer {

name: 'input-data'

type: 'Python'

top: 'data'

top: 'im_info'

top: 'gt_boxes'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+1

}

}

3、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage2_fast_rcnn_train.pt

代码一

layer {

name: 'data'

type: 'Python'

top: 'data'

top: 'rois'

top: 'labels'

top: 'bbox_targets'

top: 'bbox_inside_weights'

top: 'bbox_outside_weights'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+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: 16 #按训练集类别改,该值为类别数+1

weight_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: 64 #按训练集类别改,该值为(类别数+1)*4

weight_filler {

type: "gaussian"

std: 0.001

}

bias_filler {

type: "constant"

value: 0

}

}

}

4、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage2_rpn_train.pt

layer {

name: 'input-data'

type: 'Python'

top: 'data'

top: 'im_info'

top: 'gt_boxes'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+1

}

}

5、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: 16 #按训练集类别改,该值为类别数+1

}

}

代码二

layer {

name: "bbox_pred"

type: "InnerProduct"

bottom: "fc7"

top: "bbox_pred"

inner_product_param {

num_output: 64 #按训练集类别改,该值为(类别数+1)*4

}

}

6、py-faster-rcnn/lib/datasets/pascal_voc.py

下面这是要修改的:

class pascal_voc(imdb):

def __init__(self, image_set, year, devkit_path=None):

imdb.__init__(self, 'voc_' + year + '_' + image_set)

self._year = year

self._image_set = image_set

self._devkit_path = self._get_default_path() if devkit_path is None \

else devkit_path

self._data_path = os.path.join(self._devkit_path, 'VOC' + self._year)

self._classes = ('__background__', # always index 0

'你的标签1','你的标签2',你的标签3','你的标签4'

)

上面要改的地方是

修改训练集文件夹:

self._data_path = os.path.join(self._devkit_path, 'VOC'+self._year)

用你的数据集直接替换原来VOC2007内的Annotations,ImageSets和JPEGImages即可,就用修改了,以免出现各种错误。

修改标签:

self._classes = ('__background__', # always index 0

'你的标签1','你的标签2','你的标签3','你的标签4'

)

7、py-faster-rcnn/lib/datasets/imdb.py修改

该文件的append_flipped_images(self)函数修改为:

def append_flipped_images(self):

num_images = self.num_images

widths = [PIL.Image.open(self.image_path_at(i)).size[0]

for i in xrange(num_images)]

for i in xrange(num_images):

boxes = self.roidb[i]['boxes'].copy()

oldx1 = boxes[:, 0].copy()

oldx2 = boxes[:, 2].copy()

boxes[:, 0] = widths[i] - oldx2 - 1

print boxes[:, 0]

boxes[:, 2] = widths[i] - oldx1 - 1

print boxes[:, 0]

assert (boxes[:, 2] >= boxes[:, 0]).all()

entry = {'boxes' : boxes,

'gt_overlaps' : self.roidb[i]['gt_overlaps'],

'gt_classes' : self.roidb[i]['gt_classes'],

'flipped' : True}

self.roidb.append(entry)

self._image_index = self._image_index * 2

8、学习率和迭代次数修改

至于学习率等之类的设置,可在py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt中的solve文件设置。

迭代次数可在py-faster-rcnn\tools的train_faster_rcnn_alt_opt.py中修改:

max_iters = [80000, 40000, 80000, 40000]

分别为4个阶段(rpn第1阶段,fast rcnn第1阶段,rpn第2阶段,fast rcnn第2阶段)的迭代次数。可改成你希望的迭代次数。

如果改了这些数值,最好把py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt里对应的solver文件(有4个)也修改,stepsize小于上面修改的数值。

训练前其他说明:

为防止与之前的模型搞混,训练前把output文件夹删除,还要把py-faster-rcnn/data/cache中的文件和

py-faster-rcnn/data/VOCdevkit2007/annotations_cache中的文件删除(如果有的话)。

 

八、开始训练(以ZF网络为例)

进入py-faster-rcnn,执行:

./experiments/scripts/faster_rcnn_alt_opt.sh 0 ZF pascal_voc

 

九、测试(以ZF网络为例)

将训练得到的py-faster-rcnn\output\faster_rcnn_alt_opt\***_trainval中ZF的ZF_faster_rcnn_final.caffemodel拷贝至py-faster-rcnn\data\faster_rcnn_models(如果没有这个文件夹,就新建一个),然后修改:

py-faster-rcnn\tools\demo.py,主要修改:

CLASSES = ('__background__',

 '你的标签1', '你的标签2', '你的标签3', '你的标签4')

NETS = {'vgg16': ('VGG16',

'VGG16_faster_rcnn_final.caffemodel'),

'zf': ('ZF',

'ZF_faster_rcnn_final.caffemodel')} 

上面ZF的caffemodel改成你的caffemodel。没做修改就不改。

im_names = ['test1.jpg','test2.jpg']

改成你的测试图片。(测试图片放在py-faster-rcnn\data\demo中)。也可自己看代码再修改。

开始测试:

在py-faster-rcnn下,执行:

./tools/demo.py --net zf

如果不出错的话就会显示检测结果。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/xt/ub/9648.shtml

相关文章
最新文章
遐想小新air pro 13的安装 遐想小新air pro 13的安装

时间:2021-01-23

 运行以下命令安装和升级 运行以下命令安装和升级

时间:2021-01-23

如果你使用的是Kubuntu 17 如果你使用的是Kubuntu 17

时间:2021-01-23

 5.我能从 Windows/OS X 切换到 5.我能从 Windows/OS X 切换到

时间:2021-01-23

它将仅搜索 LTS 版本 它将仅搜索 LTS 版本

时间:2021-01-23

所有CA都必须在颁发特定域 所有CA都必须在颁发特定域

时间:2021-01-23

而不是Ubuntu 17.10上的Unit 而不是Ubuntu 17.10上的Unit

时间:2021-01-23

 对Wndows用户来说 对Wndows用户来说

时间:2021-01-23

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

Ubuntu16.04配置py-faster-rcnn

2020-12-27 编辑:网友投稿

本来用的Ubuntu14.04,毕竟都说14比16稳定嘛。但是配置好了后,运行demo.py都没问题了,但是训练的时候出现 

TypeError numpy.float64 object cannot be interpreted as an index

都说是numpy版本问题,得用1.11.0,因此降到1.11.0(sudo pip install -U numpy==1.11.0)

但是装了numpy1.11.0后出现

numpy.core.multiarray failed to import 

网上都说版本不兼容,得升级到新版本。升级又出现上面那个问题。

我就无语了,上面两个是循环的问题啊,无法解决。

卡了好几天,最后通过apt-cache show python-numpy,查看到numpy版本居然是1.8!无论怎么更新,就算通过

import numpy

numpy.__version__

显示的都不是1.8。但其实内核是1.8,因为Ubuntu14只能支持到1.8,所以放弃了Ubuntu14

 

一、必要配置安装

CUDA、opencv我的其他文章已经写过了,也可参考网上其他教程,这里就跳过。

 

二、安装一些包

pip install cython

pip install easydict

apt-get install python-opencv

还有些包根据错误提示安装就好了。

 

三、下载py-faster-rcnn

使用git clone,保证caffe分支一起clone下来

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

 

四、进入py-faster-rcnn/lib

make

 

五、进入py-faster-rcnn\caffe-fast-rcnn

cp Makefile.config.example Makefile.config

然后配置Makefile.config:是否用CUDNN、是否是opencv3

重要的一点是必须

WITH_PYTHON_LAYER :=1

配置好后,执行:

make -j8 && make pycaffe

 

六、下载VOC2007数据集

(当然也可以直接用自己的数据集)

百度网盘下载VOC2007:

把VOC2007数据集放在py-faster-rcnn\data目录下,用自己的数据集替换VOC2007数据集。(替换py-faster-rcnn\data\VOCdevkit2007\VOC2007目录下的Annotations,ImageSets和JPEGImages)

 

六、下载ImageNet数据集下预训练得到的模型参数(用来初始化训练参数)

百度网盘下载地址:

解压后将该文件放在py-faster-rcnn\data下

 

七、训练参数修改(以ZF网络为例)

1、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_fast_rcnn_train.pt

代码一

layer {

name: 'data'

type: 'Python'

top: 'data'

top: 'rois'

top: 'labels'

top: 'bbox_targets'

top: 'bbox_inside_weights'

top: 'bbox_outside_weights'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+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: 16 #按训练集类别改,该值为类别数+1

weight_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: 64 #按训练集类别改,该值为(类别数+1)*4

weight_filler {

type: "gaussian"

std: 0.001

}

bias_filler {

type: "constant"

value: 0

}

}

}

2、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rpn_train.pt

layer {

name: 'input-data'

type: 'Python'

top: 'data'

top: 'im_info'

top: 'gt_boxes'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+1

}

}

3、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage2_fast_rcnn_train.pt

代码一

layer {

name: 'data'

type: 'Python'

top: 'data'

top: 'rois'

top: 'labels'

top: 'bbox_targets'

top: 'bbox_inside_weights'

top: 'bbox_outside_weights'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+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: 16 #按训练集类别改,该值为类别数+1

weight_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: 64 #按训练集类别改,该值为(类别数+1)*4

weight_filler {

type: "gaussian"

std: 0.001

}

bias_filler {

type: "constant"

value: 0

}

}

}

4、py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage2_rpn_train.pt

layer {

name: 'input-data'

type: 'Python'

top: 'data'

top: 'im_info'

top: 'gt_boxes'

python_param {

module: 'roi_data_layer.layer'

layer: 'RoIDataLayer'

param_str: "'num_classes': 16" #按训练集类别改,该值为类别数+1

}

}

5、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: 16 #按训练集类别改,该值为类别数+1

}

}

代码二

layer {

name: "bbox_pred"

type: "InnerProduct"

bottom: "fc7"

top: "bbox_pred"

inner_product_param {

num_output: 64 #按训练集类别改,该值为(类别数+1)*4

}

}

6、py-faster-rcnn/lib/datasets/pascal_voc.py

下面这是要修改的:

class pascal_voc(imdb):

def __init__(self, image_set, year, devkit_path=None):

imdb.__init__(self, 'voc_' + year + '_' + image_set)

self._year = year

self._image_set = image_set

self._devkit_path = self._get_default_path() if devkit_path is None \

else devkit_path

self._data_path = os.path.join(self._devkit_path, 'VOC' + self._year)

self._classes = ('__background__', # always index 0

'你的标签1','你的标签2',你的标签3','你的标签4'

)

上面要改的地方是

修改训练集文件夹:

self._data_path = os.path.join(self._devkit_path, 'VOC'+self._year)

用你的数据集直接替换原来VOC2007内的Annotations,ImageSets和JPEGImages即可,就用修改了,以免出现各种错误。

修改标签:

self._classes = ('__background__', # always index 0

'你的标签1','你的标签2','你的标签3','你的标签4'

)

7、py-faster-rcnn/lib/datasets/imdb.py修改

该文件的append_flipped_images(self)函数修改为:

def append_flipped_images(self):

num_images = self.num_images

widths = [PIL.Image.open(self.image_path_at(i)).size[0]

for i in xrange(num_images)]

for i in xrange(num_images):

boxes = self.roidb[i]['boxes'].copy()

oldx1 = boxes[:, 0].copy()

oldx2 = boxes[:, 2].copy()

boxes[:, 0] = widths[i] - oldx2 - 1

print boxes[:, 0]

boxes[:, 2] = widths[i] - oldx1 - 1

print boxes[:, 0]

assert (boxes[:, 2] >= boxes[:, 0]).all()

entry = {'boxes' : boxes,

'gt_overlaps' : self.roidb[i]['gt_overlaps'],

'gt_classes' : self.roidb[i]['gt_classes'],

'flipped' : True}

self.roidb.append(entry)

self._image_index = self._image_index * 2

8、学习率和迭代次数修改

至于学习率等之类的设置,可在py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt中的solve文件设置。

迭代次数可在py-faster-rcnn\tools的train_faster_rcnn_alt_opt.py中修改:

max_iters = [80000, 40000, 80000, 40000]

分别为4个阶段(rpn第1阶段,fast rcnn第1阶段,rpn第2阶段,fast rcnn第2阶段)的迭代次数。可改成你希望的迭代次数。

如果改了这些数值,最好把py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt里对应的solver文件(有4个)也修改,stepsize小于上面修改的数值。

训练前其他说明:

为防止与之前的模型搞混,训练前把output文件夹删除,还要把py-faster-rcnn/data/cache中的文件和

py-faster-rcnn/data/VOCdevkit2007/annotations_cache中的文件删除(如果有的话)。

 

八、开始训练(以ZF网络为例)

进入py-faster-rcnn,执行:

./experiments/scripts/faster_rcnn_alt_opt.sh 0 ZF pascal_voc

 

九、测试(以ZF网络为例)

将训练得到的py-faster-rcnn\output\faster_rcnn_alt_opt\***_trainval中ZF的ZF_faster_rcnn_final.caffemodel拷贝至py-faster-rcnn\data\faster_rcnn_models(如果没有这个文件夹,就新建一个),然后修改:

py-faster-rcnn\tools\demo.py,主要修改:

CLASSES = ('__background__',

 '你的标签1', '你的标签2', '你的标签3', '你的标签4')

NETS = {'vgg16': ('VGG16',

'VGG16_faster_rcnn_final.caffemodel'),

'zf': ('ZF',

'ZF_faster_rcnn_final.caffemodel')} 

上面ZF的caffemodel改成你的caffemodel。没做修改就不改。

im_names = ['test1.jpg','test2.jpg']

改成你的测试图片。(测试图片放在py-faster-rcnn\data\demo中)。也可自己看代码再修改。

开始测试:

在py-faster-rcnn下,执行:

./tools/demo.py --net zf

如果不出错的话就会显示检测结果。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/xt/ub/9648.shtml

相关文章

风云图片

推荐阅读

返回ubuntu/debian频道首页