-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_list.py
83 lines (69 loc) · 2.59 KB
/
make_list.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import glob
import os
import random
def make_train_test():
train_name = 'train_dataset_4.txt'
test_name = 'test_dataset_4.txt'
epilepsy_path = '../datasets/mice/dataset_4/pre_case'
normal_path = '../datasets/mice/dataset_4/pre_control'
train_ratio = 0.75
train_epi_samples = []
test_epi_samples = []
for ori_path, fold, items in os.walk(epilepsy_path):
video_num = len(items)
random.shuffle(items)
train_epi_samples = sorted(items[:int(video_num*train_ratio)])
test_epi_samples = sorted(items[int(video_num*train_ratio):])
for ori_path, fold, items in os.walk(normal_path):
video_num = len(items)
random.shuffle(items)
train_norm_samples = sorted(items[:int(video_num*train_ratio)])
test_norm_samples = sorted(items[int(video_num*train_ratio):])
print('Making train list')
file = open(train_name, 'w')
for i in train_norm_samples:
line = os.path.join(normal_path.split('/')[-1], i[:-4])+' #0'
file.write(line)
file.write('\n')
for i in train_epi_samples:
line = os.path.join(epilepsy_path.split('/')[-1], i[:-4])+' #1'
file.write(line)
file.write('\n')
print('Train list done')
print('Making test list')
file = open(test_name, 'w')
for i in test_norm_samples:
line = os.path.join(normal_path.split('/')[-1], i[:-4])+' #0'
file.write(line)
file.write('\n')
for i in test_epi_samples:
line = os.path.join(epilepsy_path.split('/')[-1], i[:-4])+' #1'
file.write(line)
file.write('\n')
print('Test list done')
def make_new_test():
test_name = 'dataset/mice_labels/test_C22_0930.txt'
dir_path = '../dataset/mice/C22_0930/'
case_path = 'pre_case'
control_path = 'pre_control'
print('Making list {}'.format(test_name))
file = open(test_name, 'w')
if os.path.exists(os.path.join(dir_path, control_path)):
v_control_spl = sorted(os.listdir(os.path.join(dir_path, control_path)))
for i in v_control_spl:
line = os.path.join(control_path, i[:-4]) + ' #0'
file.write(line)
file.write('\n')
if os.path.exists(os.path.join(dir_path, case_path)):
v_case_spl = sorted(os.listdir(os.path.join(dir_path, case_path)))
for i in v_case_spl:
line = os.path.join(case_path, i[:-4])+' #1'
file.write(line)
file.write('\n')
file.close()
print('list {} is done'.format(test_name))
def main():
# make_train_test()
make_new_test()
if __name__ == "__main__":
main()