cocodataset / cocoapi

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

Loading results from a list of annotations instead of loading .json from disk #195

Open IssamLaradji opened 6 years ago

IssamLaradji commented 6 years ago

The current api allows me to load the results from a json file path, example

resFile = "results.json"
cocoDt = cocoGt.loadRes(resFile)

Is there a way I could load the results given a a list of annotations?

annList = [{"image_id":12, ....}]
cocoDt = cocoGt.loadRes(annList)

Thanks.

salihkaragoz commented 6 years ago

My code like this and it accepts list

my_results = []
for i, idx, pose_score, k in anything:
    image_data = {
                'image_id': idx,
                'bbox': bboxes[i],
                'score': pose_score,
                'category_id': 1,
                'keypoints': k.tolist()
            }
    my_results.append(image_data)

coco_pred = coco.loadRes(my_results)
IssamLaradji commented 6 years ago

I get this error

ipdb> cocoGt.loadRes(annList)
Loading and preparing results...
*** NameError: name 'unicode' is not defined

I think this error is because Python 3 doesn't have the keyword unicode. This happens in line 308 where the following conditional is checked: if type(resFile) == str or type(resFile) == unicode:

Dicko87 commented 3 years ago

Hi there guys, did anyone manage to get this to work? I am using DETR and trying to replicate the validation results by running the model in eval mode on the validation set again but my results are not the same.