-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsplit_data.py
More file actions
39 lines (32 loc) · 1.15 KB
/
split_data.py
File metadata and controls
39 lines (32 loc) · 1.15 KB
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
import os
import random
from config.config import WEBSITES_DATASET_PATH
from shutil import copyfile
BASE_FOLDER = '/workspace/data_local/websites2'
if not os.path.isdir(BASE_FOLDER):
os.mkdir(BASE_FOLDER)
TRAIN_FOLDER = '/workspace/data_local/websites2/train'
if not os.path.isdir(TRAIN_FOLDER):
os.mkdir(TRAIN_FOLDER)
VAL_FOLDER = '/workspace/data_local/websites2/val'
if not os.path.isdir(VAL_FOLDER):
os.mkdir(VAL_FOLDER)
for folder in os.listdir(WEBSITES_DATASET_PATH):
print(folder)
source_folder = os.path.join(WEBSITES_DATASET_PATH, folder)
dest_val_folder = os.path.join(VAL_FOLDER, folder)
if not os.path.isdir(dest_val_folder):
os.mkdir(dest_val_folder)
dest_train_folder = os.path.join(TRAIN_FOLDER, folder)
if not os.path.isdir(dest_train_folder):
os.mkdir(dest_train_folder)
filelist = os.listdir(source_folder)
random.shuffle(filelist)
for idx in range(200):
src = os.path.join(source_folder, filelist[idx])
dst = os.path.join(dest_val_folder, filelist[idx])
copyfile(src, dst)
for idx in range(200,1200):
src = os.path.join(source_folder, filelist[idx])
dst = os.path.join(dest_train_folder, filelist[idx])
copyfile(src, dst)