-
Notifications
You must be signed in to change notification settings - Fork 0
/
Augment.py
30 lines (22 loc) · 1.08 KB
/
Augment.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
import tensorflow as tf
# Define the input layer
input_layer = tf.placeholder(tf.float32, shape=[None, None, None, 3])
# Create a list of rotated images
rotations = [tf.contrib.image.rotate(input_layer, angles=angle) for angle in range(-10, 11, 2)]
# Create a list of random hue adjustments
hue_deltas = [tf.image.random_hue(input_layer, max_delta=0.03 * i) for i in range(0, 5)]
# Create a list of random brightness adjustments
brightness_deltas = [tf.image.random_brightness(input_layer, max_delta=0.1 * i) for i in range(0, 5)]
# Create a list of horizontally flipped images
flips = [tf.image.flip_left_right(input_layer)]
# Initialize an empty list to store the augmentations
augmentations = []
# Iterate over the rotated images
for rotated in rotations:
# Apply the hue and brightness adjustments and flipping to each rotated image
for hue in hue_deltas:
for brightness in brightness_deltas:
for flip in flips:
augmentations.append(hue(brightness(flip(rotated))))
# Concatenate the augmentations along the batch dimension
augmented_input = tf.concat(augmentations, axis=0)