yolo官网 https://pjreddie.com/darknet/yolo/
- 下载darknet 以及VOCdevkit 按官网跑通
- 准备自己的VOC数据集,可以在本地先建立一个如下格式的文件夹
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