Where the crop box goes decides what a face swap keeps
Most face swap pipelines take a detection box, pad it, resize to a fixed input, and paste the result back. Every one of those steps is a place where information is destroyed, and the padding is the step people tune least
Most face swap pipelines take a detection box, pad it, resize to a fixed input, and paste the result back. Every one of those steps is a place where information is destroyed, and the padding is the step people tune least.
A tight box around the face cuts off the jaw, the ears and the hairline. The network then has to invent the edges of the thing it was asked to draw, and it invents them by extrapolating skin tone from whatever is nearest. That is where the soft halo around a swapped face comes from: not the blend, the input.
Padding the box by 30 to 50 percent of its width gives the network context to work with, at the cost of resolution on the face itself. A 512 input over a padded box is maybe 380 pixels of actual face. For video, that trade is usually worth it. For a still, cropping tighter and running at 1024 is usually better.
The mask is the second decision. A feathered mask hides the seam but also hides the error, so a bad blend can look acceptable at a glance and wrong on a second look. A hard mask exposes the seam immediately and makes the parameters easier to tune. If you are debugging, hard mask first, feather later.
Paste-back is where the colour drifts. The output is in the model's own colour space, and dropping it into the original without a match leaves a face a few points warmer or cooler than the neck. Matching the mean and standard deviation of the lab channels over the mask region, before any sharpening, fixes most of it.
Order matters more than any single setting: detect, pad, resize, swap, match colour, composite, and only then sharpen. Sharpening before the composite amplifies the mismatch instead of hiding it.
A short checklist:
- Look at the box before the swap. If the chin or the hairline is clipped, the result is already limited.
- Keep the padded box aspect ratio close to the model's training aspect. Squashing the crop changes the face shape.
- Match colour over the mask, not over the whole image.
- Composite at the original resolution, not at the model resolution.
- Save a lossless intermediate. Re-encoding before you judge the result makes the seams harder to find.
None of this is specific to one model. It is the same set of decisions in every pipeline, and it explains most of the difference between two tools that use the same network.
I wrote this up while testing faceswapai.com, which does photo, video and GIF swaps, up to ten faces in one group shot, HD with no watermark.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.