代码:
"""
针对行李箱原先的数据集,调整有无拉杆的标注
"""
import json
data_dir = {"labels": []}
json_path = r"C:\Users\9ling\Desktop\LuggageDataset_hasrod\test\has_luggage\baiyun_airport\baiyun_airport.json"
data = json.load(open(json_path))["labels"]
final_json = r"C:\Users\9ling\Desktop\LuggageDataset_hasrod\test\has_luggage\baiyun_airport.json"
for sanno in data:
data_dir["labels"].append({"annotations": [], "filename": sanno["filename"]})
for pes in sanno["annotations"]:
if pes["class"] == "pedestrain":
luggage_anno = pes["subclass"]
data_dir["labels"][-1]["annotations"].append(pes)
data_dir["labels"][-1]["annotations"].extend(pes["subclass"])
json_test_str = json.dumps(data_dir, indent=4)
with open(final_json, 'w') as json_file:
json_file.write(json_test_str)