【debug】目标检测任务报错TypeError: Argument ‘bb‘ has incorrect type (expected numpy.ndarray, got list)

17 篇文章 2 订阅
8 篇文章 0 订阅

🚀Debug专栏

        其他debug记录请参考上方【debug专栏】

目录

🚀Debug专栏

🍀🍀背景

❓❓报错

🌻🌻解决方案

1.分析原因

2.增加条件判断

至此就解决该问题了😎😎

3.如果还报错,比如ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (15,) + inhomogeneous part.

4. 报错原因分析

5.继续修改代码

6.修改后完整python代码

至此真的就没有bug了,如果有,留言我们一起debug


🍀🍀背景

        调用ann2RLE函数时,有的识别结果像素非常小,没有过滤,直接转RLE格式的txt文本格式,报错TypeError: Argument ‘bb‘ has incorrect type (expected numpy.ndarray, got list)

❓❓报错

        详细报错信息:

        pycocotools 包处调用coco.py 报错TypeError: Argument 'bb' has incorrect type (expected numpy.ndarray, got list)


🌻🌻解决方案

1.分析原因

        报这个错误是传入的segment点是四个以内(包含四个)的会触发的错误。

2.增加条件判断

        找到环境安装位置/data/XXX/anaconda3/envs/openmmlab/lib/python3.8/site-packages/pycocotools-2.0-py3.8-linux-x86_64.egg/pycocotools的coco.py文件,修改420行,增加条件判断就好了✔️。

        python代码展示如下:

if len(segm[0])<5:

    segm[0].append(0)

        修改后python完整代码如下:

    def annToRLE(self, ann):
        """
        Convert annotation which can be polygons, uncompressed RLE to RLE.
        :return: binary mask (numpy 2D array)
        """
        t = self.imgs[ann['image_id']]
        h, w = t['height'], t['width']
        segm = ann['segmentation']
        if len(segm[0])<5:           #增加此行
            segm[0].append(0)        #增加此行
        if type(segm) == list:
            # polygon -- a single object might consist of multiple parts
            # we merge all parts into one mask rle code
            rles = maskUtils.frPyObjects(segm, h, w)
            rle = maskUtils.merge(rles)
        elif type(segm['counts']) == list:
            # uncompressed RLE
            rle = maskUtils.frPyObjects(segm, h, w)
        else:
            # rle
            rle = ann['segmentation']
        return rle

至此就解决该问题了😎😎


3.如果还报错,比如ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (15,) + inhomogeneous part.

比如我的新报错信息:

  报错信息:File "pycocotools/_mask.pyx", line 303, in pycocotools._mask.frPyObjects
  File "pycocotools/_mask.pyx", line 265, in pycocotools._mask.frPoly
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (15,) + inhomogeneous part.

4. 报错原因分析

        说我的数据是不均匀的,打印了以下segm才发现,是因为我的数据里有长度为3的list,也就是说我的数据中有两个点甚至一个点组成的目标,显然这不是我关心的目标,因为他太小了,所以我索性在这把这种样本删除了。

5.继续修改代码

        增加如下python代码,把各种情况都考虑到。

if len(segm[0])==4:    #如果差一个点,可以补全

    segm[0].append(0)

elif len(segm[0])<4:   #如果差好几个,索性删掉

    segm.remove(segm[0])

6.修改后完整python代码

        完整python代码如下:

def annToRLE(self, ann):
        """
        Convert annotation which can be polygons, uncompressed RLE to RLE.
        :return: binary mask (numpy 2D array)
        """
        t = self.imgs[ann['image_id']]
        h, w = t['height'], t['width']
        segm = ann['segmentation']
#-------------------修改位置----------------------------
        if len(segm[0])==4:    #如果差一个点,可以补全
            segm[0].append(0)
        elif len(segm[0])<4:   #如果差好几个,索性删掉
            segm.remove(segm[0])
#-------------------修改位置----------------------------
        if type(segm) == list:
            # polygon -- a single object might consist of multiple parts
            # we merge all parts into one mask rle code
            rles = maskUtils.frPyObjects(segm, h, w)
            rle = maskUtils.merge(rles)
        elif type(segm['counts']) == list:
            # uncompressed RLE
            rle = maskUtils.frPyObjects(segm, h, w)
        else:
            # rle
            rle = ann['segmentation']
        return rle

至此真的就没有bug了,如果有,留言我们一起debug


整理不易,欢迎一键三连!!!


送你们一条美丽的--分割线--

🌷🌷🍀🍀🌾🌾🍓🍓🍂🍂🙋🙋🐸🐸🙋🙋💖💖🍌🍌🔔🔔🍉🍉🍭🍭🍋🍋🍇🍇🏆🏆📸📸⛵⛵⭐⭐🍎🍎👍👍🌷🌷

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zy_destiny

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值