Step‑by‑Step Guide to Facial Expression Transfer with PaddleGAN
This tutorial walks you through cloning PaddleGAN, installing dependencies, configuring PaddlePaddle and PaddleHub, running the expression‑transfer script, and post‑processing the output video or GIF with ffmpeg, while highlighting key parameters and platform considerations.
In this tutorial we demonstrate how to use Baidu's open‑source PaddleGAN project to perform facial expression transfer and generate a video.
First, clone the PaddleGAN source code from Gitee (or obtain it via the WeChat public account by replying “蚂蚁呀嘿”).
# From Gitee clone PaddleGAN code
git clone https://gitee.com/paddlepaddle/Place the cloned PaddleGAN folder into a PyCharm project and open a terminal in that directory.
# Open the folder
cd PaddleGAN
# Install required Python packages
pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
pip install imageio-ffmpeg -i https://mirror.baidu.com/pypi/simpleCreate an output directory where the generated video will be saved.
# Create output folder
cd applications/
mkdir outputInstall Baidu's PaddlePaddle and PaddleHub, which provide the deep‑learning framework and the face‑detection model.
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install paddlehub -i https://mirror.baidu.com/pypi/simpleRun the following command (adjust the paths to your own project) to transfer the facial motions from a driving video to a source image:
export PYTHONPATH=$PYTHONPATH:../PycharmProjects/mayiyahei/PaddleGAN && \
python -u tools/first-order-demo.py \
--driving_video ../PycharmProjects/mayiyahei/MaYiYaHei.MP4 \
--source_image ../PycharmProjects/mayiyahei/input.jpeg \
--relative --adapt_scaleThe command‑line arguments are:
driving_video : video whose facial expressions will be transferred.
source_image : the image that receives the transferred expressions.
relative : use relative key‑point coordinates (recommended).
adapt_scale : adapt motion scale based on the convex hull of key points.
After the video is generated (without audio), merge it with an audio track using ffmpeg:
ffmpeg -i MaYiYaHei.mp4 -i MYYH.mp3 -vcodec copy -acodec copy result.mp4To create a GIF, run:
ffmpeg -ss 0 -t 8 -i result.mp4 -s 600x400 -r 15 result.gifNote that the facial‑expression transfer can be time‑consuming, especially on CPU‑only machines.
Feel free to experiment with different source images and driving videos to produce personalized videos or GIFs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
