问题
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