cocodataset / cocoapi

COCO API - Dataset @ http://cocodataset.org/
Other
6.05k stars 3.75k forks source link

Convert annotations RLE format (.json) #66

Closed scholltan closed 7 years ago

scholltan commented 7 years ago

hi all, I want to know how to convert annotations of my own data into the RLE format (.json). thx

vchiley commented 7 years ago

For one instance of an annotation:

from pycocotools import mask as maskUtils
import json

segmentation = maskUtils.encode(msk)
mskDic = {"image_id": int(image_id),
                  "category_id": category_id,
                  "segmentation": segmentation,
                  "score": float(score)}

with open('ouputFile.json', 'w') as json_file:
        json.dump(mskDic, json_file)

for more loop through the annotations and create a list of annotations then do the dump

is that what you were asking?

meetps commented 6 years ago

The value corresponding to the key 'segmentation' in the minival json file is a list of floats, but the maskUtils.encode(msk) returns a dictionary with keys 'counts' and 'size'. How to convert the dictionary into the segmentation list as in minival.json

raninbowlalala commented 6 years ago

@meetshah1995 Have you convert the segmentaion list as minival.json successfully?

waspinator commented 6 years ago

how would you encode masks to uncompressed RLE for use when iscrowd=1?

ray-lee-94 commented 5 years ago

I meet the same problem. I can't dump the compressed RLE in the JSON file

ZP-Guo commented 4 years ago

Hi, @vchiley, Recently I use cocoapi to evaluate my results, but I do not how to get the "score" that comes from mskDic = {"image_id": int(image_id), "category_id": category_id, "segmentation": segmentation, "score": float(score)}. And my net does not output confidence or probability. I am looking forward to your reply.