栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

labelimg中标签怎么改名字_怎么批量修改标签?

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

labelimg中标签怎么改名字_怎么批量修改标签?

在使用Labelme标注数据时,把所有的标签都写错了 然后就借鉴了一下大佬的代码

只用修改主函数里面的变量就OK了

# -*- encoding: utf-8 -*-
import os
import json


def Edit_label(json_dir,new_label = 'Maize'):

    json_files = os.listdir(json_dir)
    json_dict = {}
    for json_file in json_files:

        #  只获取json文件
        if json_file[-4:] != 'json':
            continue
        jsonfile = json_dir + '/' + json_file
        with open(jsonfile, 'r', encoding='utf-8') as jf:
            info = json.load(jf)

            # 找到位置进行修改
            for i, label in enumerate(info['shapes']):
                info['shapes'][i]['label'] = new_label

            # 使用新字典替换修改后的字典
            json_dict = info

        # 将替换后的内容写入原文件
        with open(jsonfile, 'w') as fw:
            json.dump(json_dict, fw)



if __name__ == '__main__':
    #  文件夹目录
    json_dir = r'E:DatasetsObject_ detection'
    new_label = 'Maize'
    Edit_label(json_dir,new_label)
    print('OK!')

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/786926.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号