yoloX obj_struct[“difficult“] = int(obj.find(“difficult“).text)问题解决

yoloX obj_struct[“difficult”] = int(obj.find(“difficult”).text)问题解决

yoloX模型默认运行到10个epoch有一个测试,然后我是在测试的时候报错,报错位置在voc_eval.py文件下,相对位置为:

yolox/evaluators/voc_eval.py

报这个错主要原因是标签文件.xml中没有difficult这个类,我们可以直接简单粗暴地注释掉报错行24,即

 # obj_struct["difficult"] = int(obj.find("difficult").text)

但是如果直接这样还是会报错,因为下面还是用到了difficult类。大约在100-110行的位置

    # extract gt objects for this class
    class_recs = {}
    npos = 0
    for imagename in imagenames:
        R = [obj for obj in recs[imagename] if obj["name"] == classname]
        bbox = np.array([x["bbox"] for x in R])
        difficult = np.array([x["difficult"] for x in R]).astype(np.bool)
        det = [False] * len(R)
        npos = npos + sum(~difficult)
        class_recs[imagename] = {"bbox": bbox, "difficult": difficult, "det": det}

因为difficult类是用来判断该object是不是困难样本的,我们如果xml里面没有这个类,那我们可以认为所有object都是不困难的。因此可以这样改:

    # extract gt objects for this class
    class_recs = {}
    npos = 0
    for imagename in imagenames:
        R = [obj for obj in recs[imagename] if obj["name"] == classname]
        bbox = np.array([x["bbox"] for x in R])
        # difficult = np.array([x["difficult"] for x in R]).astype(np.bool)
        difficult = np.array([0 for x in R]).astype(np.bool)
        det = [False] * len(R)
        npos = npos + sum(~difficult)
        class_recs[imagename] = {"bbox": bbox, "difficult": difficult, "det": det}

这样就OK了。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值