import json import csv import pandas as pd # header = ['img_id','label','score','x1','x2','y1','y2'] # 读取json文件 with open('path.json', 'r') as f: data = json.load(f) image_id = [] cate = [] score = [] x1m = [] x2m =[] y1m = [] y2m = [] # with open('rcnn.csv','w',encoding='UTF8') as f: # writer = csv.writer(f) # writer.writerow(header) # 循环控制写入单元格 for list_item in data: for key, value in list_item.items(): if key == "image_id": image_id.append(value) elif key == "category_id": cate.append(value) elif key == "score": score.append( value) elif key == "bbox": x1 = value[0] x2 = value[0]+value[2] y1 = value[1] y2 = value[1]+value[3] x1m.append(x1) x2m.append(x2) y1m.append(y1) y2m.append(y2) dateframe = pd.DataFrame({"img_id":image_id,'label':cate,'score':score,'x1':x1m,'x2':x2m,'y1':y1m,'y2':y2m}) dateframe.to_csv('path.csv',sep=',',index=False)
将json文件(coco的标签)写入csv文件
最新推荐文章于 2023-06-04 21:46:48 发布