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

2017年12月20日 09:48:22 上大蛋蛋 阅读数:5079 标签: faster-r-cnn
 

博主之前在跑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 训练中的一些问题及解决办法

 
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21089969/article/details/69422624

今天使用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的更多相关文章

  1. 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] # 检出人脸区域后 ...

  2. python报错 TypeError: string indices must be integers

    所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({})             #检查不是字典 如果是字典,再看看有没有这样的属性: ...

  3. macTypeError: slice indices must be integers or None or have an index method

    一般是由于Numpy的版本太高了(1.12对此进行了调整),有的时候传入numpy array里面的索引可能是浮点数,这个时候最好检查一下索引强制转换为int类型 或者安装低版本的numpy sudo ...

  4. 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 ...

  5. [转载]UEditor报错TypeError: me.body is undefined

    本文转载来自:UEditor报错TypeError: me.body is undefined 今天在使用UEditor的setContent的时候报错,报错代码如下 TypeError: me.bo ...

  6. appium 提示报错“TypeError: 'unicode' object is not callable”的解决方式!

    这里提到的这个报错,是小错误且容易经常会犯,有时需要特别注意使用. 目的要求结果:根据某个元素的id值获取到对应id的text值,并且将获取的text值与本身存在的text值做比较,查看text值是否 ...

  7. VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法

    正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...

  8. python报错 TypeError: a() got multiple values for argument 'name'

    [问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError:  got multiple values for argument 只是很简单的调用 from tsu2Ru ...

  9. firefox浏览器中使用vux的x-input报错TypeError: _this3.$refs.input.scrollIntoViewIfNeeded is not a function

    最近做公众号项目,想着统一风格,所以决定使用vux. 在调试时发现,只要鼠标点击x-input输入框,就会报错 TypeError: _this3.$refs.input.scrollIntoView ...

随机推荐

  1. mongdb 4.x admin密码忘记,如何 重建admin用户

    在mongo db中,或mongo db cluser中,如果admin密码忘记了,必须按下面的步骤来做.思路为注释掉security认证部分,重启mongo server, 重建admin用户,再打 ...

  2. endnote的使用

    下载网址: https://support.clarivate.com/Endnote/s/article/EndNote-Installer-download?language=en_US 关联of ...

  3. Go语言 Note

    1.简单的CURD之搭建基础框架 //路由层 func Router(rg *gin.RouterGroup){ rg.GET("/getsupplier", facility.G ...

  4. 025、MySQL字符串大小写转化函数,文本转化大写,文本转化小写

    #变大写 SELECT UPPER('abcdABCD123a'); #ABCDABCD123A SELECT UCASE('abcdABCD123a'); #ABCDABCD123A #变小写 SE ...

  5. wincc的服务器-客户机模式具体做法(全抄-未测试)

    一.原来的工作方式:在同一工作组中4台计算机其windows名分别为A.B.C.D且都已安装好wincc5.0+sp2,原来在每台计算机上运行的均是单用户,4台计算机上实际运行的是一个相同的项目,最先 ...

  6. memortstream Base64编码和filestream base64编码不同

    memorystream base64 function BaseImage(fn: string): string; var   m1: TMemoryStream;   m2: TStringSt ...

  7. 读取多张MNIST图片与利用BaseEstimator基类创建分类器

    读取多张MNIST图片 在读取多张MNIST图片之前,我们先来看下读取单张图片如何实现 每张数字图片大小都为28 * 28的,需要将数据reshape成28 * 28的,采用最近邻插值,如下 def ...

  8. 印度第一颗CPU横空出世!阵势庞大

    我们忙着推进国产芯片的同时,隔壁的印度也没闲着.作为印度顶级高校的印度理工学院(IIT)之马德拉斯校区已经发布了其首颗处理器“Shakti”(代表女性力量的印度神话人物)的SDK软件开发包,并承诺会很 ...

  9. mapper.xml实现oracle的分页语句

    当我们用常规方法进行分页查询时,虽然在数据库可以分页查询出来数据, 如下语句 <!-- 分页查询所有 --> <select id="findAllPage" r ...

  10. 洛谷[Luogu] 普及村总结

    总结 简单的模拟 交叉模拟 排序 排序EX