本文主要是介绍labelme篇---批量修改用labelme标注的标签,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
labelme篇—批量修改用labelme标注的标签
labelme标注后的标签格式如下图:
我们要改的就是label
所以代码如下
# -*- coding: utf-8 -*-
import os
import jsonjson_dir = '' # JSON文件所在文件夹的路径
old_label = '' # 要修改的旧标签名
new_label = '' # 修改后的新标签名# 遍历JSON文件夹中的所有JSON文件
for filename in os.listdir(json_dir):if filename.endswith('.json'):json_path = os.path.join(json_dir, filename)# 读取JSON文件with open(json_path, 'r', encoding='utf-8') as f:data = json.load(f)# 遍历每个标注对象if 'shapes' in data:shapes = data['shapes']for obj in shapes:if obj['label'] == old_label:# 修改标签名obj['label'] = new_label# 保存修改后的JSON文件with open(json_path, 'w', encoding='utf-8') as f:json.dump(data, f, ensure_ascii=False, indent=4)print('标签名修改完成!')
这篇关于labelme篇---批量修改用labelme标注的标签的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!