-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtraining_data.py
31 lines (24 loc) · 1.02 KB
/
training_data.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 numpy
from image_augmentation import random_transform
from image_augmentation import random_warp
random_transform_args = {
'rotation_range': 10,
'zoom_range': 0.05,
'shift_range': 0.05,
'random_flip': 0.4,
}
def get_training_data(images, batch_size):
indices = numpy.random.randint(len(images), size=batch_size)
for i, index in enumerate(indices):
image = images[index]
#print("before transform size is {}".format(image.shape))
image = random_transform(image, **random_transform_args)
#print("after transform size is {}".format(image.shape))
warped_img, target_img = random_warp(image)
#print("after warp size is {}".format(warped_img.shape))
if i == 0:
warped_images = numpy.empty((batch_size,) + warped_img.shape, warped_img.dtype)
target_images = numpy.empty((batch_size,) + target_img.shape, warped_img.dtype)
warped_images[i] = warped_img
target_images[i] = target_img
return warped_images, target_images