-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_aug.py
More file actions
35 lines (29 loc) · 1.04 KB
/
data_aug.py
File metadata and controls
35 lines (29 loc) · 1.04 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
import tensorflow as tf
import random
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
from skimage import exposure
def keras_pre(x_train,
batch_size,
zoom_range=0.2,
shear_range=0.2,
rotation_range=10,
horizontal_flip=False,
vertical_flip=False):
def random_contrast_aug(im):
im = exposure.rescale_intensity(im, out_range=(0, 1))
amount = 2**((random.random() - 0.5) * 4) # 2** -2 to 2
return exposure.adjust_gamma(im, amount)
genargs = dict(
# brightness_range=0.1,
rotation_range=rotation_range,
zoom_range=zoom_range,
shear_range=shear_range,
horizontal_flip=horizontal_flip,
vertical_flip=vertical_flip,
fill_mode='nearest',
preprocessing_function=random_contrast_aug)
xgen = ImageDataGenerator(**genargs)
xgen.fit(x_train, augment=True, seed=0)
xflow = xgen.flow(x_train, batch_size=batch_size, seed=0, shuffle=False)
return xflow