-
Notifications
You must be signed in to change notification settings - Fork 14
/
train_datagen.py
91 lines (68 loc) · 2.39 KB
/
train_datagen.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Place all train datagenerators here
import numpy as np
from tensorflow.keras.preprocessing.image import ImageDataGenerator
def datagen_img_roi1_roi2(Xtrain_img, Xtrain_roi1, Xtrain_roi2, ytrain, batch_size):
while True:
idx = np.random.permutation(Xtrain_img.shape[0])
datagen = ImageDataGenerator(
rotation_range=8,
width_shift_range=0.08,
height_shift_range=0.08,
shear_range=0.1,
zoom_range=0.08,
horizontal_flip=True,
)
batches = datagen.flow(Xtrain_img[idx], ytrain[idx], batch_size=batch_size, shuffle=False)
idx0 = 0
for batch in batches:
idx1 = idx0 + batch[0].shape[0]
yield [batch[0], Xtrain_roi1[idx[idx0:idx1]], Xtrain_roi2[idx[idx0:idx1]], ], batch[1]
idx0 = idx1
if idx1 >= Xtrain_img.shape[0]:
break
def datagen_img_roi1_roi2_hogfeat(Xtrain_img, Xtrain_roi1, Xtrain_roi2, Xtrain_hogfeat, ytrain, batch_size):
while True:
idx = np.random.permutation(Xtrain_img.shape[0])
datagen = ImageDataGenerator(
rotation_range=8,
width_shift_range=0.08,
height_shift_range=0.08,
shear_range=0.1,
zoom_range=0.08,
horizontal_flip=True,
)
batches = datagen.flow(Xtrain_img[idx], ytrain[idx], batch_size=batch_size, shuffle=False)
idx0 = 0
for batch in batches:
idx1 = idx0 + batch[0].shape[0]
yield [batch[0], Xtrain_roi1[idx[idx0:idx1]], Xtrain_roi2[idx[idx0:idx1]], Xtrain_hogfeat[idx[idx0:idx1]], ], batch[1]
idx0 = idx1
if idx1 >= Xtrain_img.shape[0]:
break
train_datagen = {
"1": ImageDataGenerator(
rotation_range=10,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=True,
),
"2": ImageDataGenerator(
rotation_range=8,
width_shift_range=0.08,
height_shift_range=0.08,
shear_range=0.1,
horizontal_flip=True,
),
"3": ImageDataGenerator(
rotation_range=5,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=True,
),
"4": datagen_img_roi1_roi2,
"5": datagen_img_roi1_roi2_hogfeat,
}