-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_augmenter.py
More file actions
50 lines (40 loc) · 1.92 KB
/
data_augmenter.py
File metadata and controls
50 lines (40 loc) · 1.92 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
40
41
42
43
44
45
46
47
48
49
50
from augment import *
import os
import time
dataDir = 'data/wallpapers'
checkpointDir = 'modelCheckpoints'
Symmetry_Groups = {'P1', 'P2', 'PM', 'PG', 'CM', 'PMM', 'PMG', 'PGG', 'CMM',
'P4', 'P4M', 'P4G', 'P3', 'P3M1', 'P31M', 'P6', 'P6M'}
train_folder = 'train'
test_folder = 'test'
train_aug_folder = 'train_aug'
test_aug_folder = 'test_aug'
print('Augmenting data...')
if not os.path.exists(os.path.join(dataDir,train_aug_folder)):
os.mkdir(os.path.join(dataDir,train_aug_folder))
for label in Symmetry_Groups:
if not os.path.exists(os.path.join(dataDir, train_aug_folder,label)):
os.mkdir(os.path.join(dataDir, train_aug_folder,label))
if not os.path.exists(os.path.join(dataDir,test_aug_folder)):
os.mkdir(os.path.join(dataDir,test_aug_folder))
for label in Symmetry_Groups:
if not os.path.exists(os.path.join(dataDir, test_aug_folder,label)):
os.mkdir(os.path.join(dataDir, test_aug_folder,label))
start = time.time()
for label in Symmetry_Groups:
for root, _, filenames in os.walk(os.path.join(dataDir, train_folder, label)):
for file in filenames:
for i in range(20):
aug_img = augmentImage(cv2.imread(os.path.join(root,file)), scale=64)
cv2.imwrite(os.path.join(dataDir, train_aug_folder, label, file.replace('.png', '_' + str(i+1) + '.png')), aug_img)
end = time.time()
print(str(end - start) + ' seconds taken to augment training data.')
start = time.time()
for label in Symmetry_Groups:
for root, _, filenames in os.walk(os.path.join(dataDir, test_folder, label)):
for file in filenames:
for i in range(20):
aug_img = augmentImage(cv2.imread(os.path.join(root, file)), scale=64)
cv2.imwrite(os.path.join(dataDir, test_aug_folder, label, file.replace('.png', '_' + str(i+1) + '.png')), aug_img)
end = time.time()
print(str(end - start) + ' seconds taken to augment testing data.')