资源简介
KITTI数据集转化为VOC数据集,用于yolo训练,目标检测,相关介绍在博客中http://blog.csdn.net/baolinq
代码片段和文件信息
# create_train_test_txt.py
# encoding:utf-8
import pdb
import glob
import os
import random
import math
def get_sample_value(txt_name category_name):
label_path = ‘./Labels/‘
txt_path = label_path + txt_name+‘.txt‘
try:
with open(txt_path) as r_tdf:
if category_name in r_tdf.read():
return ‘ 1‘
else:
return ‘-1‘
except IOError as ioerr:
print(‘File error:‘+str(ioerr))
txt_list_path = glob.glob(‘./Labels/*.txt‘)
txt_list = []
for item in txt_list_path:
temp1temp2 = os.path.splitext(os.path.basename(item))
txt_list.append(temp1)
txt_list.sort()
print(txt_list end = ‘\n\n‘)
# 有博客建议train:val:test=8:1:1,先尝试用一下
num_trainval = random.sample(txt_list math.floor(len(txt_list)*9/10.0)) # 可修改百分比
num_trainval.sort()
print(num_trainval end = ‘\n\n‘)
num_train = random.sample(num_trainvalmath.floor(len(num_trainval)*8/9.0)) # 可修改百分比
num_train.sort()
print(num_train end = ‘\n\n‘)
num_val = list(set(num_trainval).difference(set(num_train)))
num_val.sort()
print(num_val end = ‘\n\n‘)
num_test = list(set(txt_list).difference(set(num_trainval)))
num_test.sort()
print(num_test end = ‘\n\n‘)
pdb.set_trace()
Main_path = ‘./ImageSets/Main/‘
train_test_name = [‘trainval‘‘train‘‘val‘‘test‘]
category_name = [‘Car‘‘Pedestrian‘‘Cyclist‘]
# 循环写trainvl train val testc
for item_train_test_name in train_test_name:
list_name = ‘num_‘
list_name += item_train_test_name
train_test_txt_name = Main_path + item_train_test_name + ‘.txt‘
try:
# 写单个文件
with open(train_test_txt_name ‘w‘) as w_tdf:
# 一行一行写
for item in eval(list_name):
w_tdf.write(item+‘\n‘)
# 循环写Car Pedestrian Cyclist
for item_category_name in category_name:
category_txt_name = Main_path + item_category_name + ‘_‘ + item_train_test_name + ‘.txt‘
with open(category_txt_name ‘w‘) as w_tdf:
# 一行一行写
for item in eval(list_name):
w_tdf.write(item+‘ ‘+ get_sample_value(item item_category_name)+‘\n‘)
except IOError as ioerr:
print(‘File error:‘+str(ioerr))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-30 20:41 kitti转为VOC\
文件 2363 2017-12-14 13:01 kitti转为VOC\create_train_test_txt.py
文件 2138 2017-12-20 10:13 kitti转为VOC\kitti_label.py
文件 2079 2017-12-14 12:31 kitti转为VOC\modify_annotations_txt.py
文件 4056 2017-12-14 12:55 kitti转为VOC\txt_to_xm
评论
共有 条评论