-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgen_list.py
More file actions
43 lines (32 loc) · 975 Bytes
/
gen_list.py
File metadata and controls
43 lines (32 loc) · 975 Bytes
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
38
39
40
41
42
43
# import os
# root_dir = '/home/yuedy13/Desktop/result'
# subdir_list = [o for o in os.listdir(root_dir) if os.path.isdir(os.path.join(root_dir,o))]
# out_file = open('list.txt', 'w')
# for x in subdir_list:
# current_folder = os.path.join(root_dir, x)
# file_list = [os.path.join(x, f) for f in os.listdir(current_folder) if os.path.isfile(os.path.join(current_folder, f))]
# lable = 0
# if x >= 'a':
# lable = ord(x) - ord('a') + 10
# else:
# lable = int(x)
# for y in file_list:
# out_file.write(y + ' ' + str(lable) + '\n')
# out_file.close()
import random
radio = 0.07
infile = open('list.txt', 'r')
lines = infile.readlines()
infile.close()
random.shuffle(lines)
num = (int)(len(lines) * radio)
test_list = lines[0:num]
train_list = lines[num+1:]
test_file = open('test_list.txt', 'w')
for x in test_list:
test_file.write(x)
test_file.close()
train_file = open('train_list.txt', 'w')
for x in train_list:
train_file.write(x)
train_file.close()