【已解决】IndexError: boolean index did not match indexed array along dimension 0; dimension is 128 but

问题描述 

Traceback (most recent call last):
File "/home/visionx/nickle/temp/SimCLR/linear_evaluation.py", line 233, in <module>
plt.scatter(t_sne_embeddings[node_labels == class_id, 0],
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: boolean index did not match indexed array along dimension 0; dimension is 128 but corresponding boolean dimension is 49920

原因分析和解决

        这个原因到是很好分析:就是索引对不上,indexError嘛,那为什么索引对不上呢?

        我们看一下报错信息就知道了,这个错误是和node_labels密切相关的,这个看名字大概能猜出来是对某个内容的标签,其实就是所取数据,那既然是取数据,总有一定的数量对吧,按照cv习惯的处理方法,其实就是分batch进行操作,那结果是什么对不上了呢?我们就得分析整个过程是怎么样的。

        我们再进行模型加载,或者预训练模型加载的时候是把批量的特征存储进来的,批量是多少?128,那就和报错信息内容对应上了,那为什么还有一个49920呢?这个时候我们留个心眼除一下就知道了,正好的390,也就是说按照128每batch去取,取了390次正好可以训练一个轮次,在验证的时候是把一个轮次epoch而不是一个批次batch,那明白了这一点就好处理了。

        我们把对应部分的代码放到batch里面就可以了

        再次运行,就没有这个问题了,当然,如果出现其他问题,就解决其他问题。 

bug无处不在,debug至死不渝

扩展阅读

        1、很正常的数目对不上

        其实这类错误是因为使用布尔类型对具体位置进行索引时,被索引的个数和布尔个数不对应。(a组数列有10个,bool只有6个,因此报错),让二者一致就可以了   

布尔索引错误_indexerror: boolean index did not match indexed ar-CSDN博客文章浏览阅读1.2w次,点赞4次,收藏6次。IndexError: boolean index did not match indexed array along dimension 0; dimension is 10 but corresponding boolean dimension is 6这类错误是因为使用布尔类型对具体位置进行索引时,被索引的个数和布尔个数不对应。(a组数列有10个,bool只有6个,因此报错)正确操作:把布尔个数改成十个..._indexerror: boolean index did not match indexed array along dimension 0; dimhttps://blog.csdn.net/qiyanzhi/article/details/107174548

        2、是因为实际应用的数据集的问题

        比如说这个:

mask-rcnn在训练过程中,突然中断报错,提示:boolean index did not match indexed array along dimension 0;dimension is.._indexerror: boolean index did not match indexed ar-CSDN博客文章浏览阅读6.1k次。一、环境:win10 + gpu 3090 + maskrcnn + tensorflow2.6.0;二、报错信息如下:IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 2image_id 549image_id 85 8/20 [===========>............_indexerror: boolean index did not match indexed array along dimension 0; dimhttps://blog.csdn.net/shanxiderenheni/article/details/123857542

完结撒花

        我很想你,但我不能告诉你,我不能输了人,还输了阵

  • 9
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值