import os
import json
import cv2
from lxml import etree
import xml.etree.cElementTree as ET
import time
import pandas as pd
from tqdm import tqdm
anno = "annotations_without_background.json"
xml_dir = "anno_xml/"
#Create anno dir
dttm = time.strftime("%Y%m%d%H%M%S", time.localtime())
if os.path.exists(xml_dir):
os.rename(xml_dir,xml_dir+dttm)
os.mkdir(xml_dir)
# Read json file
import json
with open(anno,'r') as load_f:
f = json.load(load_f)
imgs = f['images']
df_cate = pd.DataFrame(f['categories'])
df_cate_sort = df_cate.sort_values(["id"],ascending=True)
categories = list(df_cate_sort['name'])
df_anno = pd.DataFrame(f['annotations'])
#anno_list = list(annos.itertuples(index=False))
#print(anno_list[0]['id'])
for i in tqdm(range(len(imgs))):
xml_content = []
file_name = img
coco的json label转换为VOC的xml格式
最新推荐文章于 2024-06-29 14:21:41 发布
本文介绍了如何将COCO格式的JSON标注转换为VOC XML格式,适用于计算机视觉任务中数据集的转换,以便于在VOC工具链下进行模型训练和验证。
摘要由CSDN通过智能技术生成