python批量修改labelme json格式标签

之前打算用mask-rcnn跑一个数据集,标注方式出点问题   使用labelname1,labelname2这种的标注模式  现在要改成labelname   group_id:1这种,还不是自己标的也不好意思在让别人去改     图片太多  手工一个。先能用  后期再优化一下。用上正则和多线程  还有CPython

以下是代码  

import json
import os

path = './'
dirs = os.listdir(path)



def dateset():
    num_flag = 0
    for file in dirs: # 循环读取路径下的文件并筛选输出
        if os.path.splitext(file)[1] == ".json": # 筛选图片文件
            num_flag = num_flag +1
    
            print("path ===== ",file)
            # print(os.path.join(path,file))
            with open(os.path.join(path,file),'r') as load_f:
    
                load_dict = json.load(load_f)
            n=len(load_dict['shapes'])
           
            for i in range (0,n):
                
                ###钢筋###
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks1':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '1'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks2':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '2'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks3':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '3'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks4':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '4'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks5':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '5'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks6':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '6'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks7':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '7'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks8':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '8'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks9':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '9'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks10':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '10'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks11':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '11'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks12':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '12'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks13':
                    load_dict['shapes'][i]['label'] = 'flat_bar_with_hooks'
                    load_dict['shapes'][i]['group_id'] = '13'
                
                if load_dict['shapes'][i]['label'] == 'flat_bar_with_hooks14':
       
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值