forked from qqwweee/keras-yolo3
-
Notifications
You must be signed in to change notification settings - Fork 9
/
make_train_files.py
37 lines (32 loc) · 1003 Bytes
/
make_train_files.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
37
import os
import pandas
main_dir = 'VOCDevkit/VOC2007/ImageSets/Main'
os.chdir(main_dir)
pwd = os.getcwd()
print(pwd)
def make_train_files():
suffixs = ['_train','_val','_test']
for suffix in suffixs:
print('suffix',suffix)
new_file = open('{}.txt'.format(suffix.replace('_','')),'w')
text = ""
for file in os.listdir():
if file.find(suffix) == -1:continue
with open(file) as f:
if text == "":text = f.read()
text =text +'\n'+ f.read()
new_file.write(text)
def split_val_test(rate:float):
val = pandas.read_csv('val.txt')
val = val.sample(frac=1)
print('len',len(val))
split = int(len(val) * rate)
test = val.values
val[:split].to_csv('val.txt',index=False)
val[split:].to_csv('test.txt',index=False)
print('val.txt',split)
print('test.txt',len(val) - split)
if __name__ == '__main__':
val_rate = 0.33
make_train_files()
split_val_test(val_rate)