coco的json label转换为VOC的xml格式

本文介绍了如何将COCO格式的JSON标注转换为VOC XML格式,适用于计算机视觉任务中数据集的转换,以便于在VOC工具链下进行模型训练和验证。
摘要由CSDN通过智能技术生成
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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值