Project · AI & ML
Motion Transfer
Making one person perform another's tai chi: a skeleton taken from the source video drives four image generators trained on the target.
- Ref.
- 01.02
- Period
- Nov 2024
- Status
- Completed
- Organization
- M2 AI — UCBL
- Contributors
- Axel COLMANT and Mohamed Massamba SENE
- Stack
- Python
- PyTorch
- MediaPipe
- OpenCV
Key points
- MediaPipe skeleton of a source person, turned into images of a target person.
- Four generators compared: nearest frame, a decoder from coordinates, a U-Net and a GAN.
- Side-by-side video of the four generators on the same source clip.
The task
Take a video of one person dancing, and make another person, filmed elsewhere, perform the same moves. This was a practical for Alexandre Meyer's deep learning for images course, done as a team of two with Mohamed Massamba Sene. It follows “Everybody Dance Now” (Chan et al., ICCV 2019), and was chosen as a way into GANs: instead of jumping to the final model, the assignment climbs there in four steps, each one answering the limits of the previous one.
The course gave us the plumbing: MediaPipe for the skeletons, the code that cuts a video into frames paired with their skeleton, and a demo that plays the result. Our job was the generators themselves, the function that receives a skeleton and must return an image of the target person in that pose, and their training. The paper's extra work on smooth motion over time and on faces was left out of the assignment on purpose.
Our pair: a tai chi video of a person in yellow on a stage as the source of the moves (Video 1), and a person in white on a lawn as the target to animate (Video 2).
Skeletons and training pairs
The link between the two videos is the skeleton. MediaPipe returns 33 landmarks per person, face and fingers included. We keep the 13 that carry the pose: nose, shoulders, elbows, wrists, hips, knees and ankles (Fig. 1).
A generator can receive them in two forms. As 26 numbers, the x and y of each joint, which is compact but says nothing about where things sit in the picture. Or as a skeleton image: the bones painted in colour on a black 128 × 128 image.
With these skeletons, the target video is first turned into training data (Video 3). MediaPipe finds the skeleton of the person, and one frame in 20 is kept: it is cropped to 128 × 128 around the skeleton, and the skeleton is stored with the crop. Out of 14,967 frames, this gives 736 pairs, the frames where a body was found. Each pair says “this pose looks like this picture”: the skeleton is the input, the frame is the answer a generator must learn to give. Later, the same extraction runs on every frame of the source video, and its skeletons are what the trained generator receives.
Why not feed the network the source frame itself? Because it shows the source dancer: the face, the yellow clothes, the stage. During training, the input and the expected output would then be the same target frame, so the network would only learn to copy its input. The skeleton image keeps the pose and nothing else, looks the same whether it comes from the target or the source video, and is already lined up pixel for pixel with the image to produce.
Four generators, four steps
The four steps of the assignment, in order (Table 1). Our networks all output a 128 × 128 colour image and are trained with Adam (learning rate 0.0002, batches of 32).
| Generator | Input | Loss | Epochs |
|---|---|---|---|
| 1 · Nearest frame | skeleton | — | — |
| 2 · Skeleton → image | 26 numbers | L1 | 50 |
| 3 · Image → image | skeleton image, 128 × 128 | L1 | 50 |
| 4 · GAN | skeleton image, 128 × 128 | 100 × L1 + adversarial | 10 |
Nearest frame
If the target video held every possible pose, there would be nothing to learn: find the stored frame whose skeleton is closest to the source one, and show it. That is the first step, with no network at all. Every image is real, so it looks right, but the search goes through every stored frame, nothing links one frame to the next, and a pose the target never made has no answer. Hence the next steps: a network that can draw poses it has never seen.
Skeleton → image
The most direct network takes the 26 numbers and produces an image. The assignment suggested a small decoder to 64 × 64 and warned not to spend long on it. We went to 128 × 128: the numbers are expanded into a 4 × 4 map, then upsampled step by step, with a self-attention layer and three residual blocks on the way (Fig. 2). It still blurs: a list of coordinates does not tell the network where each limb sits in the picture.
Image → image
The paper's answer is to draw the skeleton as an image first, so the input is already laid out like the output. Among the improvements the assignment listed, we took a U-shaped generator with residual blocks in the middle: an encoder shrinks the skeleton image to 16 × 16, three residual blocks work on it, and a decoder grows it back into the target, with skip connections that hand the fine details of each level straight to the decoder (Fig. 3).
GAN
Trained on a pixel loss alone, the networks average the possible answers, and an average is blurry. The last step “boosts” generator 3 with a discriminator, six convolutions that judge whether an image is a real frame. The discriminator learns to tell the two apart; the generator learns to fool it while staying close to the real frame, with a loss that mixes 100 × L1 and the adversarial term, as in pix2pix (Fig. 4). It was trained for 10 epochs only, against 50 for generators 2 and 3. The assignment also suggested more stable variants, such as WGAN-GP or a least-squares loss; we kept the classic one.
What we got
Each approach fails in its own way (Fig. 5). The nearest frame is always sharp, since it is a real image, but it can only reuse poses the target already made, so the arms are often wrong. The network fed with raw coordinates follows the pose but gives a blurry ghost. Giving the skeleton as an image makes a clear difference: the network can line up the limbs with the picture, and the person gets a shape. The GAN keeps that alignment and adds texture, at the cost of a few artefacts, such as red smears where the target video carries red captions.
Over time, the differences grow (Video 4). Each frame is generated on its own, so the nearest frame holds a stored pose for several frames, then jumps to the next one. The skeleton → image network moves smoothly but stays a blur. The image → image network changes more from one frame to the next than the source clip itself, so it flickers. The GAN is steadier and keeps the most texture, but grainy noise covers the grass. This is exactly the part of the paper the assignment left aside: “Everybody Dance Now” conditions each frame on the previous one and adds a network for the face.
Climbing the four steps, each one fixed a limit of the previous one. The biggest jump came from giving the pose as an image rather than as numbers: the network no longer has to work out where each limb lands in the picture. The discriminator then traded a little stability for texture, even with five times fewer epochs. What it does not fix is resolution: at 128 × 128, the person stays small and soft, and the face is a few pixels.
We split the work between us; on my side, I trained the models, built the comparison plots, and later added the video export used for the demo.
References
- [1]Chan, Ginosar, Zhou, Efros (2019). Everybody Dance Now. ICCV
- [2]Isola, Zhu, Zhou, Efros (2017). Image-to-Image Translation with Conditional Adversarial Networks. CVPR
- [3]Alexandre Meyer. Practical subject: dance motion transfer. M2 Deep learning for images, Université Lyon 1
- [4]Google. MediaPipe Pose