File "pycocotools/_mask.pyx", line 307, in pycocotools._mask.frPyObjects Exception: input type is not supported.

 mmdetection在訓練有segmentation資料的時候,發生 File "pycocotools/_mask.pyx", line 307, in pycocotools._mask.frPyObjects Exception: input type is not supported.


主要原因為自製的segmentation資料中,可能有不符合規則的資料,coco格式中,segmentation的格式為list(list(x,y,x,y,....))每個seg至少要有四個值且必須為偶數。

下列code移除不符規定的seg

def check_coco_seg_format(json_path):
    """
    check there is invalid segmentation data in coco json file and remove invalid seg then resave it
    Args:
        json_path: path to json file

    Returns: None
    """
    with open(json_path) as fid:
        json_data = json.load(fid)
    annotations = json_data['annotations']
    for annotation in tqdm(annotations):
        segs = annotation['segmentation']
        new_segs = []
        for seg in segs:
            len_seg = len(seg)
            if len_seg % 2 == 0 and len_seg >= 4:
                new_segs.append(seg)
            if len_seg % 2 != 0:
                print('get an annotation not even.')
            if len_seg <= 4:
                print('seg len less than 4: {}'.format(len_seg))
                print('annoation: {}'.format(annotation))
        annotation['segmentation'] = new_segs
    with open(json_path, 'w', encoding='utf-8') as f:
        json.dump(json_data, f, ensure_ascii=False, indent=4)

留言

這個網誌中的熱門文章

在windows 10上安裝mmdetection