0

我正在使用https://github.com/facebookresearch/maskrcnn-benchmark提供的 Faster R-CNN 模型。在将 KITTI 数据集上的训练模型转换为 Coco 格式(2D 对象检测)后,我正在尝试评估其结果。

结果是 0 或 -1,有时它会在 CocoApi 工具包中的 g["area"] 处引发错误。

pycoco if g['ignore'] or (g['area']aRng[1]): "KeyError: 'area'"

根据我在研究问题时发现的情况,“区域”用于分割,我的数据集中没有那种注释。

我转换的注释文件的外观的一个小例子:

{
    "images": [
        {
            "file_name": "007292.png",
            "id": 1,
            "width": 1392,
            "height": 512
        },
        {
            "file_name": "000603.png",
            "id": 2,
            "width": 1392,
            "height": 512
        },
        {
            "file_name": "004313.png",
            "id": 3,
            "width": 1392,
            "height": 512
        },
        {
            "file_name": "006401.png",
            "id": 4,
            "width": 1392,
            "height": 512
        },
        {
            "file_name": "005442.png",
            "id": 5,
            "width": 1392,
            "height": 512
        }
    ],
    "annotations": [
        {
            "image_id": 1,
            "id": 1,
            "category_id": 1,
            "bbox": [
                589.08,
                176.53,
                26.719999999999914,
                26.409999999999997
            ],
            "iscrowd": 0
        },
        {
            "image_id": 1,
            "id": 2,
            "category_id": 1,
            "bbox": [
                235.9,
                190.63,
                115.16,
                57.78
            ],
            "iscrowd": 0
        },
        {
            "image_id": 1,
            "id": 3,
            "category_id": 1,
            "bbox": [
                426.57,
                184.2,
                42.0,
                26.700000000000017
            ],
            "iscrowd": 0
        },
        {
            "image_id": 2,
            "id": 4,
            "category_id": 1,
            "bbox": [
                1211.2,
                182.65,
                11.799999999999955,
                186.35
            ],
            "iscrowd": 0
        },
        {
            "image_id": 2,
            "id": 5,
            "category_id": 1,
            "bbox": [
                386.94,
                180.98,
                57.80000000000001,
                30.55000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 2,
            "id": 6,
            "category_id": 1,
            "bbox": [
                736.21,
                173.49,
                113.90999999999997,
                96.44999999999999
            ],
            "iscrowd": 0
        },
        {
            "image_id": 2,
            "id": 7,
            "category_id": 1,
            "bbox": [
                701.98,
                174.7,
                91.55999999999995,
                66.01000000000002
            ],
            "iscrowd": 0
        },
        {
            "image_id": 2,
            "id": 8,
            "category_id": 1,
            "bbox": [
                682.42,
                176.25,
                58.200000000000045,
                47.53
            ],
            "iscrowd": 0
        },
        {
            "image_id": 2,
            "id": 9,
            "category_id": 1,
            "bbox": [
                667.8,
                175.85,
                51.190000000000055,
                39.24000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 2,
            "id": 10,
            "category_id": 1,
            "bbox": [
                654.6,
                176.88,
                31.110000000000014,
                26.49000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 3,
            "id": 11,
            "category_id": 1,
            "bbox": [
                267.69,
                179.7,
                101.13,
                33.120000000000005
            ],
            "iscrowd": 0
        },
        {
            "image_id": 3,
            "id": 12,
            "category_id": 1,
            "bbox": [
                461.31,
                176.05,
                72.38000000000005,
                28.73999999999998
            ],
            "iscrowd": 0
        },
        {
            "image_id": 3,
            "id": 13,
            "category_id": 1,
            "bbox": [
                600.36,
                177.08,
                52.360000000000014,
                23.299999999999983
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 14,
            "category_id": 1,
            "bbox": [
                1061.94,
                96.68,
                179.05999999999995,
                277.32
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 15,
            "category_id": 1,
            "bbox": [
                280.52,
                184.02,
                148.01,
                96.92999999999998
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 16,
            "category_id": 1,
            "bbox": [
                143.54,
                179.75,
                350.11,
                194.25
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 17,
            "category_id": 1,
            "bbox": [
                861.45,
                139.2,
                178.20000000000005,
                64.58000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 18,
            "category_id": 1,
            "bbox": [
                1018.27,
                144.44,
                88.04999999999995,
                43.25
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 19,
            "category_id": 1,
            "bbox": [
                1061.23,
                147.01,
                100.31999999999994,
                39.27000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 20,
            "category_id": 1,
            "bbox": [
                439.12,
                184.57,
                66.10000000000002,
                43.43000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 21,
            "category_id": 1,
            "bbox": [
                381.68,
                184.81,
                98.5,
                63.59
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 22,
            "category_id": 1,
            "bbox": [
                673.9,
                172.28,
                52.389999999999986,
                36.53999999999999
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 23,
            "category_id": 1,
            "bbox": [
                473.3,
                180.94,
                49.079999999999984,
                36.900000000000006
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 24,
            "category_id": 1,
            "bbox": [
                609.73,
                179.26,
                35.860000000000014,
                27.670000000000016
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 25,
            "category_id": 1,
            "bbox": [
                668.0,
                173.81,
                88.37,
                31.150000000000006
            ],
            "iscrowd": 0
        },
        {
            "image_id": 4,
            "id": 26,
            "category_id": 1,
            "bbox": [
                585.17,
                172.42,
                40.520000000000095,
                15.630000000000024
            ],
            "iscrowd": 0
        },
        {
            "image_id": 5,
            "id": 27,
            "category_id": 1,
            "bbox": [
                192.88,
                178.88,
                74.23000000000002,
                33.49000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 5,
            "id": 28,
            "category_id": 1,
            "bbox": [
                250.68,
                179.92,
                65.70999999999998,
                26.27000000000001
            ],
            "iscrowd": 0
        },
        {
            "image_id": 5,
            "id": 29,
            "category_id": 1,
            "bbox": [
                306.54,
                178.95,
                55.48999999999995,
                22.670000000000016
            ],
            "iscrowd": 0
        }
    ],
    "categories": [
        {
            "name": "Car",
            "id": 1
        }
    ]
}

编辑:我已将 area 属性添加到标签中,计算为 bbox[2]*bbox[3],不再有错误,但结果为 0。

任何帮助将不胜感激!

4

1 回答 1

1

根据COCO官方文档的1.Detection Evaluation,AP byarea也进行了评估。

指标

因此,如果area你自己的自定义数据集中没有,下面的代码会报错site-packages/pycocotools/cocoeval.py

if g['ignore'] or (g['area']<aRng[0] or g['area']>aRng[1]):

此代码表示如果area超过上限aRng[1]或小于下限aRng[0],则从评估目标中忽略。

如果您使用自己的自定义数据集,则可能没有area基本事实。area在这种情况下,您可以根据边界框的宽度和高度创建一个。

如果您不需要评估每个区域,您可以像下面的代码一样注释掉。

# It does not evaluate for each area
# if g['ignore'] or (g['area']<aRng[0] or g['area']>aRng[1]):
if g['ignore']:
于 2020-03-22T04:35:49.283 回答