forked from QAlexBall/Faster_RCNN_for_TextDetection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_maintxt.py
36 lines (31 loc) · 919 Bytes
/
generate_maintxt.py
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
36
import os
import random
trainval_percent = 0.66
train_percent = 0.5
xmlfilepath = 'H:\\2Unsally\\MyVOC\\MyVOC2007\\Annotations'
txtsavepath = 'H:\\2Unsally\\MyVOC\\MyVOC2007\\ImageSets\\Main'
total_xml = os.listdir(xmlfilepath)
num=len(total_xml)
list=range(num)
tv=int(num*trainval_percent)
tr=int(tv*train_percent)
trainval= random.sample(list,tv)
train=random.sample(trainval,tr)
ftrainval = open('MyVOC2007\\ImageSets\\Main\\trainval.txt', 'w')
ftest = open('MyVOC2007\\ImageSets\\Main\\test.txt', 'w')
ftrain = open('MyVOC2007\ImageSets\Main\\train.txt', 'w')
fval = open('MyVOC2007\\ImageSets\\Main\\val.txt', 'w')
for i in list:
name=total_xml[i][:-4]+'\n'
if i in trainval:
ftrainval.write(name)
if i in train:
ftrain.write(name)
else:
fval.write(name)
else:
ftest.write(name)
ftrainval.close()
ftrain.close()
fval.close()
ftest .close()