faster rcnn报错:TypeError: slice indices must be integers or None or have an __index__ method
https://blog.csdn.net/qq_27637315/article/details/78849756
https://blog.csdn.net/qq_21089969/article/details/69422624
faster rcnn报错:TypeError: slice indices must be integers or None or have an __index__ method
博主之前在跑faster rcnn训练的时候别的问题都能按照网上教程解决唯独这个问题一直不行,去网上搜说是numpy有问题,我安装过conda所以我有两个numpy一个是pip安装的还有一个是conda安装的,我的python2.7使用的是conda环境下的,这个numpy坑确实不小,我对numpy一通乱改把conda装的降到了1.11.3,将pip安装的升到了1.13.3但还是不行,于是我就开始看代码改错了,我主要改的是/home/xiaohua/py-faster-rcnn/lib/roi_data_layer下的minibatch.py文件转到172行,将
for ind in inds:
cls = clss[ind]
start = 4 * cls
end = start + 4
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
return bbox_targets, bbox_inside_weights
改为:
for ind in inds:
ind = int(ind)
cls = clss[ind]
start = int(4 * cos)
end = int(start + 4)
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
return bbox_targets, bbox_inside_weights
即可,自己注意python语法格式哦。
Faster RCNN 训练中的一些问题及解决办法
今天使用Faster RCNN训练自己的数据的时候,出现了一些因为boost或者是numpy版本不兼容导致的问题,经过各种查资料和求助大神,总算是顺利把网络跑起来了。下面内容都是今天亲测出现的问题并与其对应的解决方案,和大家一起分享,也便于我以后查看。
训练方法:在配置好Faster RCNN之后,准备好自己的数据,修改网络的配置文件和相应的训练脚本满,使用end to end 的训练方法,在$py-faster-rcnn的根目录下执行:./experiments/scripts/faster_rcnn_end2end.sh 0 VGG16 pascal_voc 。以下都是执行该脚本后出现的问题。
Problem 1
AttributeError: 'module' object has no attribute ‘text_format'
- 1
解决方法:在/home/xxx/py-faster-rcnn/lib/fast_rcnn/train.py的头文件导入部分加上 :import google.protobuf.text_format
Problem 2
TypeError: 'numpy.float64' object cannot be interpreted as an index
- 1
这里是因为numpy版本不兼容导致的问题,最好的解决办法是卸载你的numpy,安装numpy1.11.0。如果你和笔者一样不是服务器的网管,没有权限的话,就只能自己想办法解决了。
修改如下几个地方的code:
1) /home/xxx/py-faster-rcnn/lib/roi_data_layer/minibatch.py
将第26行:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)
改为:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)
- 1
- 2
2) /home/xxx/py-faster-rcnn/lib/datasets/ds_utils.py
将第12行:hashes = np.round(boxes * scale).dot(v)
改为:hashes = np.round(boxes * scale).dot(v).astype(np.int)
- 1
- 2
3) /home/xxx/py-faster-rcnn/lib/fast_rcnn/test.py
将第129行: hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v)
改为: hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v).astype(np.int)
- 1
- 2
4) /home/xxx/py-faster-rcnn/lib/rpn/proposal_target_layer.py
将第60行:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)
改为:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)
- 1
- 2
Problem3
TypeError: slice indices must be integers or None or have an __index__ method
- 1
这里还是因为numpy版本的原因,最好的解决办法还是换numpy版本(见problem2),但同样也有其他的解决办法。
修改 /home/lzx/py-faster-rcnn/lib/rpn/proposal_target_layer.py,转到123行:
for ind in inds:
cls = clss[ind]
start = 4 * cls
end = start + 4
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
return bbox_targets, bbox_inside_weights
- 1
- 2
- 3
- 4
- 5
- 6
- 7
这里的ind,start,end都是 numpy.int 类型,这种类型的数据不能作为索引,所以必须对其进行强制类型转换,转化结果如下:
for ind in inds:
ind = int(ind)
cls = clss[ind]
start = int(4 * cos)
end = int(start + 4)
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
return bbox_targets, bbox_inside_weights
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
以上内容是笔者在训练自己的datasets时候出现的一些问题,大部分还是因为Faster RCNN 发布的时候使用的一些库现在都升级了,所以需要对代码中一些细节进行修改!
faster rcnn报错:TypeError: slice indices must be integers or None or have an __index__ method的更多相关文章
- TypeError: slice indices must be integers or None or have an __index__ method
由于除法/自动产生的类型是浮点型,因此出现上述错误,修正方法为,将/更改为// roi_gray_lwpCV = gray_lwpCV[y:y + h // 2, x:x + w] # 检出人脸区域后 ...
- python报错 TypeError: string indices must be integers
所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({}) #检查不是字典 如果是字典,再看看有没有这样的属性: ...
- macTypeError: slice indices must be integers or None or have an index method
一般是由于Numpy的版本太高了(1.12对此进行了调整),有的时候传入numpy array里面的索引可能是浮点数,这个时候最好检查一下索引强制转换为int类型 或者安装低版本的numpy sudo ...
- for遍历用例数据时,报错:TypeError: list indices must be integers, not dict,'int' object is not iterable解决方法
一:报错:TypeError: list indices must be integers, not dict for i in range(0,len(test_data)): suite.addT ...
- [转载]UEditor报错TypeError: me.body is undefined
本文转载来自:UEditor报错TypeError: me.body is undefined 今天在使用UEditor的setContent的时候报错,报错代码如下 TypeError: me.bo ...
- appium 提示报错“TypeError: 'unicode' object is not callable”的解决方式!
这里提到的这个报错,是小错误且容易经常会犯,有时需要特别注意使用. 目的要求结果:根据某个元素的id值获取到对应id的text值,并且将获取的text值与本身存在的text值做比较,查看text值是否 ...
- VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法
正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...
- python报错 TypeError: a() got multiple values for argument 'name'
[问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError: got multiple values for argument 只是很简单的调用 from tsu2Ru ...
- firefox浏览器中使用vux的x-input报错TypeError: _this3.$refs.input.scrollIntoViewIfNeeded is not a function
最近做公众号项目,想着统一风格,所以决定使用vux. 在调试时发现,只要鼠标点击x-input输入框,就会报错 TypeError: _this3.$refs.input.scrollIntoView ...
随机推荐
- express - 快速构建项目
1,cnpm i express -g 2, cnpm i express-generater -g 3, express - e 项目名
- SpringIOC初始化过程源码跟踪及学习
Spring版本 4.3.2,ssm框架 代码过宽,可以shift + 鼠标滚轮 左右滑动查看 web.xml <!--配置获取项目的根路径,java类中使用System.getProperty ...
- R 读取回归模型的信息
参考博客: http://blog.sina.com.cn/s/blog_8f5b2a2e0101fmiq.html https://blog.csdn.net/huangyouyu523/artic ...
- 002.让CI4框架CodeIgniter显示错误信息
01. 在public目录的index.php中,添加以下内容: //定义环境为开发模式,可以输出各种错误信息 define('ENVIRONMENT', 'development'); 02.我们在 ...
- 013、MySQL取本月最后日期,取每个月的最后一天日期
#取本月最后一天 SELECT last_day( curdate( ) ); #取上个月最后一天 , INTERVAL MONTH ) ); , INTERVAL MONTH ) ); , INTE ...
- JS: 复选框——ALL与A、B、C(选中ALL同时选中各子项)
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title> ...
- php phar反序列化任意执行代码
2018年 原理一.关于流包装stream wrapper大多数的文件操作允许使用各种URL协议去访问文件路径,如data://,zlib://,php://例如常见的有include('php:// ...
- B - Stacks of Flapjacks UVA - 120
BackgroundStacks and Queues are often considered the bread and butter of data structures and find us ...
- UVA - 12083 Guardian of Decency (二分匹配)
题意:有N个人,已知身高.性别.音乐.运动.要求选出尽可能多的人,使这些人两两之间至少满足下列四个条件之一. 1.身高差>40 2.性别相同 3.音乐不同 4.运动相同 分析: 1.很显然 ...
- 干货分享:Academic Essay写作套路详解
你想过如何中立的表达自己吗?大概只有10%不到的同学,会真正重视这个细节.但很多留学生能顺利写完作文已经不容易,还要注意什么中立不中立的.我知道这个标准,对许多同学有些过分,但很残酷的告诉你,这的确是 ...