forked from shaoanlu/faceswap-GAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraining_data.py
26 lines (21 loc) · 864 Bytes
/
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
import numpy
from image_augmentation import random_transform
from image_augmentation import random_warp
random_transform_args = {
'rotation_range': 15,
'zoom_range': 0.1,
'shift_range': 0.05,
'random_flip': 0.5,
}
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]
image = random_transform( image, **random_transform_args )
warped_img, target_img = random_warp( image )
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