-
Notifications
You must be signed in to change notification settings - Fork 1
/
split.py
30 lines (22 loc) · 842 Bytes
/
split.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
import os
import os.path
import glob
import shutil
from tqdm import tqdm
# run under the top level directory
def spliter(sz):
train_sz = sz * 8 / 10
test_sz = sz - train_sz
return train_sz, test_sz
realpaths = glob.glob('real/real/*.jpg')
pixpaths = glob.glob('real/pix/*.jpg')
train_sz, test_sz = spliter(len(realpaths))
for i, realpath in tqdm(enumerate(realpaths)):
filename = os.path.basename(realpath)
pixpath = pixpaths[i]
if i < train_sz: # train
shutil.copyfile(realpath, os.path.join('./dataset/train/real', filename))
shutil.copyfile(pixpath, os.path.join('./dataset/train/pix', filename))
else: # test
shutil.copyfile(realpath, os.path.join('./dataset/test/real', filename))
shutil.copyfile(pixpath, os.path.join('./dataset/test/pix', filename))