-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathtraining_data.py
31 lines (25 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
# based on deepfakes sample project
# https://github.com/deepfakes/faceswap
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,
}
# next batch of our train data
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 )
# first index => initiate array
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