-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfakefacemotion.py
64 lines (48 loc) · 1.67 KB
/
fakefacemotion.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import imageio
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from skimage.transform import resize
import warnings
import sys
warnings.filterwarnings("ignore")
imagename = sys.argv[1]
#print(imagename)
videoname = sys.argv[2]
# Put image name here
source_image = imageio.imread(imagename)
# Put video name here
reader = imageio.get_reader(videoname)
#Resize image and video to 256x256
source_image = resize(source_image, (256, 256))[..., :3]
fps = reader.get_meta_data()['fps']
driving_video = []
try:
for im in reader:
driving_video.append(im)
except RuntimeError:
pass
reader.close()
driving_video = [resize(frame, (256, 256))[..., :3] for frame in driving_video]
def display(source, driving, generated=None):
fig = plt.figure(figsize=(8 + 4 * (generated is not None), 6))
ims = []
for i in range(len(driving)):
cols = [source]
cols.append(driving[i])
if generated is not None:
cols.append(generated[i])
im = plt.imshow(np.concatenate(cols, axis=1), animated=True)
plt.axis('off')
ims.append([im])
ani = animation.ArtistAnimation(fig, ims, interval=50, repeat_delay=1000)
plt.close()
return ani
from demo import load_checkpoints
generator, kp_detector = load_checkpoints(config_path='vox-256.yaml',
checkpoint_path='vox-cpk.pth.tar')
from demo import make_animation
from skimage import img_as_ubyte
predictions = make_animation(source_image, driving_video, generator, kp_detector, relative=True)
#save resulting video
imageio.mimsave('finaloutput/output.mp4', [img_as_ubyte(frame) for frame in predictions])