Combine json files containing COCO person keypoint annotations

£可爱£侵袭症+ 提交于 2020-01-16 08:45:09

问题


I've annotated some images using the coco-annotator. I'd like to combine these annotations with the existing one ("person_keypoints_train2017.json" and "person_keypoints_val2017.json").

Has anyone ever managed to do so? If yes, how? (preferrably using python)


回答1:


json vlaues can be accessed using the json module try reading both the files and hence decide what values to combine:

import json
from collections import OrderedDict
filename1 = "person_keypoints_train2017.json"
with open(filename1) as f:
    data_filename1 = json.load(f, object_pairs_hook=OrderedDict)
filename2 = "person_keypoints_val2017.json"
with open(filename1) as f:
    data_filename2 = json.load(f, object_pairs_hook=OrderedDict)

now you have two dictionaries, you can manipulate data. In order to save them to the file:

    with open(file_name, 'w') as outfile:
    json.dump(data, outfile, separators=(',', ':'))


来源:https://stackoverflow.com/questions/58095457/combine-json-files-containing-coco-person-keypoint-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!