当前位置:   article > 正文

YOLOv3训练自己的VOC数据(一)——前期准备工作_goldyolo训练voc

goldyolo训练voc

yolo官网 https://pjreddie.com/darknet/yolo/

  1. 下载darknet 以及VOCdevkit 按官网跑通
  2. 准备自己的VOC数据集,可以在本地先建立一个如下格式的文件夹
    /text/aHR0c

JPEGImages和Annotations中文件名是相互对应的 如 1.jpg对应的标注是1.xml

可以使用LabelImage工具快捷生成xml文件
也可以将原本已标注的1.txt通过代码转换为1.xml
假设你原本有一个标注好的1.txt 它里面每一行的内容为“数字1 数字2 数字3 数字4 类别”
你可以使用如下的python代码将txt格式转化为xml。
label.py


#! /usr/bin/python
# -*- coding:UTF-8 -*- 

import os, sys
import glob
from PIL import Image

src_img_dir = 'D:\\study\\xmu\\design\\VOC\\JPEGImage'

src_txt_dir = 'D:\\study\\xmu\\design\\VOC\\label'
src_xml_dir ='D:\\study\\xmu\\design\\VOC\\Annotations'
 
img_Lists = glob.glob(src_img_dir + '/*.png')
 
img_basenames = [] # e.g. 100.jpg
for item in img_Lists:
    img_basenames.append(os.path.basename(item))
 
img_names = [] # e.g. 100
for item in img_basenames:
    temp1, temp2 = os.path.splitext(item)
    img_names.append(temp1)
 
for img in img_names:
    im = Image.open((src_img_dir + '/' + img + '.png'))
    width, height = im.size
 
    # open the crospronding txt file
    gt = open(src_txt_dir + '/' + img + '.txt').read().splitlines()
    #gt = open(src_txt_dir + '/gt_' + img + '.txt').read().splitlines()
 
    # write in xml file
    #os.mknod(src_xml_dir + '/' + img + '.xml')
    xml_file = open((src_xml_dir + '/' + img + '.xml'), 'w')
    xml_fil
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/728023
推荐阅读
相关标签
  

闽ICP备14008679号