之前打算用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':