-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_image_folder_structure.py
31 lines (27 loc) · 1.23 KB
/
setup_image_folder_structure.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
import os
import shutil
import numpy as np
train = os.path.join("..", "images", "train")
valid = os.path.join("..", "images", "valid")
test = os.path.join("..", "images", "test")
# transfer from train to test 80-20
train_dir = os.listdir(train)
for idx in train_dir:
num_transfers = np.ceil(len(os.listdir(os.path.join(train, idx)))*0.2).astype("int")
files_to_transfer = np.random.choice(os.listdir(os.path.join(train, idx)), num_transfers, replace=False)
for file in files_to_transfer:
shutil.move(os.path.join(train, idx, file), os.path.join(test, idx))
# transfer from train to valid 80-20
train_dir = os.listdir(train)
for idx in train_dir:
num_transfers = np.ceil(len(os.listdir(os.path.join(train, idx)))*0.2).astype("int")
files_to_transfer = np.random.choice(os.listdir(os.path.join(train, idx)), num_transfers, replace=False)
for file in files_to_transfer:
shutil.move(os.path.join(train, idx, file), os.path.join(valid, idx))
# revert folder image structure
# change source and dest(ination)
# revert = os.listdir(source)
# for idx in revert:
# files = os.listdir(os.path.join(source, idx))
# for file in files:
# shutil.move(os.path.join(source, idx, file), os.path.join(dest, idx, file))