Skip to content

Instantly share code, notes, and snippets.

@edgeboyo
Created October 20, 2020 13:48
Show Gist options
  • Save edgeboyo/f8bc3eaad08b07d410db2f0dbdf5a422 to your computer and use it in GitHub Desktop.
Save edgeboyo/f8bc3eaad08b07d410db2f0dbdf5a422 to your computer and use it in GitHub Desktop.
import imageio
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from skimage.transform import resize
# from IPython.display import HTML
import warnings
warnings.filterwarnings("ignore")
source_image = imageio.imread(input("Point to source picture: "))
reader = imageio.get_reader(input("Point to trainer video: ))
#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]
from demo import load_checkpoints
generator, kp_detector = load_checkpoints(config_path='config/vox-256.yaml',
checkpoint_path='damedame/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('../generated.mp4', [img_as_ubyte(frame) for frame in predictions], fps=fps)
#video can be downloaded from /content folder
# HTML(display(source_image, driving_video, predictions).to_html5_video())
pip install PyYAML==5.3.1
git clone https://github.com/AliaksandrSiarohin/first-order-model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment