forked from Oldpan/Faceswap-Deepfake-Pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraining_data.py
27 lines (21 loc) · 851 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
27
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]
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