import os
import json
def get_car_json_info(data_dir):
all_json=os.listdir(data_dir)
print(len(all_json))
trucklist = [ "car", "truck"] # 正确标签,注意顺序
for j_name in all_json:
with open(data_dir + j_name,'r',encoding='utf-8') as j:
info=json.load(j)
# print(j_name)
slist = info["shapes"]
# 查找错误标签
for i in range(len(slist)):
# print(slist[i]["label"])
if slist[i]["label"] in trucklist :
continue
else:
print(j_name)
# 修改car 为 Car
for i in range(len(slist)):
# print(slist[i]["label"])
if slist[i]["label"] == "bus":
info["shapes"][i]["label"] = "car"
with open(data_dir + j_name,'w',encoding='utf-8') as f:
json.dump(info, f, ensure_ascii=False)
get_car_json_info("F:/ew/dataset_new/Annotations/")
07-22
3478