Spaces:
Running

aditya-rAj19 commited on
Commit
74dd70d
·
1 Parent(s): b60d8aa

Fix the empty hair matte, and stop pasting hair when HairFastGAN is unavailable

Browse files

Two separate hair problems, found by running the pipeline on real photos.

_soft_hair_matte parsed a very wide crop so long hair wouldn't be cut off before
parsing, but that also shrinks the head inside the 512x512 parse input and takes
BiSeNet's hair confidence down with it. On a 66x77 face the matte peaked at
0.341 — nothing at all above the 0.4 that swap_hair thresholds at — so the mask
came out empty and hair transfer silently did nothing at all. It now keeps the
wide crop when it is confident and tightens only when it is not; across five
test photos the matte went from 0.341/0.00% usable to 0.75-0.84, all usable.

That alone made things worse, though: with a mask to work from, the fallback
path warps the source's hair straight into the scene and composites a smeared,
semi-transparent blob over the head — the pasted-hair artifact this project has
been chasing. It is plainly worse than keeping the target's hair, which the
clean face swap already produces.

So the fallback is gone. Hair is transferred only when HairFastGAN actually
returns a portrait; otherwise the target's hair is kept and the reason is
logged. The matte fix still matters there, since that path parses the generated
portrait. HairFastGAN currently fails on the Space because it connects to the
public ZeroGPU Space anonymously and hits its quota — setting HF_TOKEN (or
HAIRFAST_SPACE) is what turns real hair transfer back on.

14 tests pass.

2 files changed +39 -13
Files changed (2)
core/head_swap.py+30-12
web_app.py+9-1