全网最全的yolo系列转换工具,从txt转xml,再从xml转txt,亲自测试好用

        在训练yolo的过程中,难免涉及标注的数据格式转化,经过了几次修改和迭代,最终把转化代码跟大家一起分享。

        先把xml转txt部分的代码分享一下,py_convert_xml2txt.py:

# -*- coding:utf-8 -*-

import os
import shutil
import cv2
import numpy as np
import xml.etree.ElementTree as ET

wordname_coco = ['person','bicycle','car','motorbike','aeroplane','bus','train','truck','boat','traffic light','fire hydrant',
                 'stop sign','parking meter','bench','bird','cat','dog','horse','sheep','cow','elephant','bear', 'zebra','giraffe',
                 'backpack','umbrella','handbag','tie','suitcase','frisbee','skis','snowboard','sports ball','kite','baseball bat',
                 'baseball glove','skateboard','surfboard','tennis racket','bottle','wine glass','cup','fork','knife','spoon','bowl',
                 'banana','apple','sandwich','orange','broccoli','carrot','hot dog','pizza','donut','cake','chair','sofa','potted plant',
                 'bed','dining table','toilet','tv','laptop','mouse','remote','keyboard','cell phone','microwave','oven','toaster','sink',
                 'refrigerator','book','clock','vase','scissors','teddy bear','hair drier','toothbrush']

wordname_voc = ['aeroplane','bicycle','bird','boat','bottle','bus','car','cat','chair','cow','diningtable','dog','horse',
                'motorbike','person','pottedplant','sheep','sofa','sheep','train','tvmonitor']

wordname_zkrc = ['person','car','cat','dog']

#person car truck cat dog

def convert(size, box):
    dw = 1. / (size[0])
    dh = 1. / (size[1])
    x = (box[0] + box[1]) / 2.0 - 1
    y = (box[2] + box[3]) / 2.0 - 1
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x * dw
    w = w * dw
    y = y * dh
    h = h * dh

    return (x, y, w, h)

def convert_xml2txt_voc():

    #text_dir = './data/JPEGImages/'
    xml_dir = "./data/LR_person_car_dataset/train/"
    imagedir = "./data/LR_person_car_dataset/train/"
    out_txt_dir = './InfraredData/txt/'
    out_temp_txt_dir = './InfraredData/temp_Txt/'
    out_images_dir = './InfraredData/Images/'

    title = "20240823_4_"
    count = 0
    list = os.listdir(xml_dir)  # 列出文件夹下所有的目录与文件
    for i in range(0, len(list)):
        name = os.path.splitext(list[i])
        if name[1] == '.xml':
            print(list[i])
            #changeTitle = title + str(i + 1) + "_"
            xml_path = xml_dir + list[i]
            jpg_path = imagedir + name[0] + '.jpg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值