feat: GFPGAN face-identity restoration post-pass

Add an optional, commercial-safe face-restoration post-pass that recovers
face identity the diffusion removal pass drifts (canny holds structure, not
likeness) while still scrubbing the pixel watermark in the face regions.

- face_restore.py: GFPGANer singleton (CPU unless CUDA), the basicsr
  torchvision.transforms.functional_tensor shim, and the pure feather
  _composite_faces helper (unit-tested without the model). GFPGAN
  re-synthesizes each face from a StyleGAN2 prior, so composited face pixels
  are GAN-generated (no watermark, no pixel-copy) -- oracle-clean at weight 0.5
  with identity preserved.
- InvisibleEngine.remove_watermark: restore_faces / restore_faces_weight,
  best-effort, auto-skips when the extra is absent or no face is detected.
- CLI --restore-faces/--no-restore-faces + --restore-faces-weight on
  invisible/all/batch (on by default).
- restore extra (gfpgan/facexlib/basicsr), numpy<2-pinned (scipy<1.18,
  numba<0.60) and kept out of `all`; basicsr needs Python <3.13 + setuptools<69
  to build, so pin .python-version 3.12.

Commercial-safe: GFPGAN Apache-2.0, RetinaFace MIT. The CodeFormer alternative
is non-commercial and is not shipped. The earlier IP-Adapter FaceID layer was
removed (footgun: needs high strength, corrupts faces at the low removal
strength).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Victor Kuznetsov
2026-06-03 16:51:52 -07:00
parent d90d5d886a
commit 411ef16ec3
11 changed files with 1624 additions and 14 deletions
+9 -6
View File
@@ -384,12 +384,15 @@ conditioning, never by copying original pixels.**
while every pixel is still regenerated -- SynthID is removed everywhere. Verified
better than plain img2img at the same strength (text stays legible where plain
garbles it), and the controlnet background scrub reads clean on the oracle.
- **Face identity:** canny holds face *structure* but not *identity*. The validated
approach (researched + prototyped 2026-06-03, not yet shipped) is a face-restoration
post-pass: CodeFormer/GFPGAN RE-SYNTHESIZES each face from a discrete codebook
(codebook pixels, not original -> scrubs SynthID) at a low fidelity weight
(`w~0.5`), composited into the cleaned image. Oracle-confirmed clean in face
regions with identity preserved. (An IP-Adapter FaceID approach was tried and
- **Face identity:** canny holds face *structure* but not *identity*. Shipped as the
optional `--restore-faces` GFPGAN post-pass (`face_restore.py`, the `restore`
extra, ON by default, auto when faces present). It runs GFPGAN on the ORIGINAL
faces and feather-composites the restored face REGIONS into the cleaned image:
GFPGAN RE-SYNTHESIZES each face from a StyleGAN2 prior (GAN pixels, not original
-> scrubs SynthID) at a low fidelity weight (`--restore-faces-weight`, default
`0.5`). Oracle-confirmed clean in face regions with identity preserved. Commercial-
safe (GFPGAN Apache-2.0 + RetinaFace MIT); the CodeFormer alternative is
NON-COMMERCIAL and is not shipped. (An IP-Adapter FaceID approach was tried and
REMOVED -- it needs high denoise strength and corrupts faces at removal strength;
see `docs/controlnet-removal-pipeline-research.md`.)