由于在制作VOC数据集时,未生成标注文件(xml),直接生成了labels,格式如下:
需将其转成如下格式:
python代码如下:
# encoding: utf-8
#将VOC数据集里的所有labels(每行中遇到空格则回车换行,最终得到一个数一行)import re
import os
path = "//home/swl/darknet_smoke/scripts/VOCdevkit/VOC2019/111111/labels-voc" #读取labels的文件夹文件夹目录
pathh = "/home/swl/darknet_smoke/scripts/VOCdevkit/VOC2019/111111/labels" #用来存放生成的labels的文件夹
files= os.listdir(path) #得到文件夹下的所有文件名称
for file in files:
if not os.path.isdir(file):
fn = open(path+"/"+file); #打开文件
fn = fn.read()
fn = fn.replace(' ','\r\n')
print(str (fn))
print(type(fn))
s = open(pathh+"/"+file,'a+');
s = s.write(fn)
#s.close()