1更换标注工具标出的json 数据 lable 由英文 转为中文 其他不变
import json
from pathlib import Path
from tqdm import tqdm
def replace(path, label_map: dict):
for path in tqdm(list(Path(path).glob('**/*.json'))):
with path.open(encoding='utf-8') as f:
jj = json.load(f)
shapes = jj['shapes']
for shape in shapes:
label = (shape['label'])
if label in label_map.keys():
shape['label'] = label_map[shape['label']]
with path.open('w', encoding='utf-8') as f:
json.dump(jj, f, indent=2, ensure_ascii=False)
label_map = {
"beaker": "烧杯",
"thermometer": "温度计",
"water_column": "水柱",
"glass_bubble": "玻璃泡",
"hand": "手",
"head": "头",
"eye": "眼睛",
}
path = r'C:\Users\ccc\Desktop\test_json\4950'
replace(path, label_map)