-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.py
More file actions
33 lines (20 loc) · 856 Bytes
/
Copy pathsplit.py
File metadata and controls
33 lines (20 loc) · 856 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
import os
import numpy as np
import shutil
rootdir = '../Data/' # path of the original folder
classes = ['focus', 'left', 'right']
for i in classes:
os.makedirs(rootdir + '/Train/' + i)
os.makedirs(rootdir + '/Test/' + i)
source = rootdir + '/' + i
allFileNames = os.listdir(source)
np.random.shuffle(allFileNames)
test_ratio = 0.25
train_FileNames, test_FileNames = np.split(np.array(allFileNames),
[int(len(allFileNames) * (1 - test_ratio))])
train_FileNames = [source+'/' + name for name in train_FileNames.tolist()]
test_FileNames = [source+'/' + name for name in test_FileNames.tolist()]
for name in train_FileNames:
shutil.copy(name, rootdir + '/Train/' + i)
for name in test_FileNames:
shutil.copy(name, rootdir + '/Test/' + i)