-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09_splitting.py
61 lines (55 loc) · 2.01 KB
/
09_splitting.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
import glob, os
from shutil import copyfile, rmtree
from random import randint
from files.utilities import printProgressBar
train_percentage = 80
files = sorted(glob.glob('./dataset/6_combined/*'))
max_subject = 0
no_of_files = len(files)
for file in files:
file = file.split("/")
file = file[len(file)-1]
if max_subject< int(file[:3]):
max_subject = int(file[:3])
test_count = round(((no_of_files/100)*(100-train_percentage)))
test_list = []
test_filelist = []
while len(test_filelist)<test_count:
rand = randint(1,max_subject+1)
if rand in test_list:
pass
else:
rand = "{:03d}".format(rand)
test_list.append(rand)
for file in files:
if file.find(rand)>=0:
test_filelist.append(file)
print(
"Random Test Subjects :",len(test_list),"\n"
"Test Percentage :",100-train_percentage,"\n"
"Train Percentage :",train_percentage,"\n"
"Test Images :",len(test_filelist),"\n"
"Train Images :",no_of_files-len(test_filelist),"\n"
"Total Files :",no_of_files)
if os.path.isdir("./dataset/7_main/"):
rmtree("./dataset/7_main/")
os.mkdir("./dataset/7_main")
os.mkdir("./dataset/7_main/test")
os.mkdir("./dataset/7_main/test/sober")
os.mkdir("./dataset/7_main/test/drunk")
os.mkdir("./dataset/7_main/train")
os.mkdir("./dataset/7_main/train/sober")
os.mkdir("./dataset/7_main/train/drunk")
printProgressBar(0, no_of_files, prefix = 'Progress:', suffix = 'Complete', length = 50)
for i, file in enumerate(files):
if file in test_filelist:
if (file.find('sober') != -1):
copyfile(file, "./dataset/7_main/test/sober/"+file.replace("./dataset/6_combined/",""))
else:
copyfile(file, "./dataset/7_main/test/drunk/"+file.replace("./dataset/6_combined/",""))
else:
if (file.find('sober') != -1):
copyfile(file, "./dataset/7_main/train/sober/"+file.replace("./dataset/6_combined/",""))
else:
copyfile(file, "./dataset/7_main/train/drunk/"+file.replace("./dataset/6_combined/",""))
printProgressBar(i + 1, no_of_files, prefix = 'Progress:', suffix = 'Complete', length = 50)