跳到正文
DEV Community· Promtix·· 2 小時前AI 評分50

AI 照片生成身份鎖的構建經驗:如何保持人物面貌一致

Keeping the Right Face: Lessons From Building an Identity Lock for AI Photo Generation

AI 導讀

Promtix 為 AI 照片生成工具設計按用途調整的身份鎖,讓參考照片中需要保留的人物特徵不被預設文字覆蓋。身份敏感且附有參考照片時,指示模型以照片為準處理膚色、年齡、體型及性別;A/B 對照顯示,啟用鎖定後膚色和年齡更貼近來源照片,場景則不受影響。髮型試戴工具採用較窄的身份鎖,不鎖定髮型;作者指出,同一原則也適用於髮色和鬍鬚工具。

正文

If you've built anything on top of reference-image models (give it a photo, get a new scene with the same person), you've probably hit this bug: the output looks like a different person. Not drastically different, just enough that the user notices immediately, because they know their own face better than any model does.

Where it comes from

Most "generate a photo in this style" products work with presets: a short text description of a scene (business portrait, studio lighting, a specific pose) plus the user's reference photo. The problem is that preset text often includes incidental descriptions of the subject, skin tone, age, hair, body type, because the person who wrote the preset was describing a scene, not writing a spec for an identity lock. When the model reads both the photo and a text description, the text can win. We saw this directly: a preset describing "bronze skin" and "an older woman" pulled a user's actual light skin tone and youthful face toward the text, even though her photo was the only real reference.

What fixed it

The fix wasn't a different model, it was a conditional instruction appended to the prompt, but only when two things are both true: the tool is identity-sensitive (a photoshoot-style tool, not a transformation tool) and a reference photo is actually attached. The instruction tells the model, explicitly, to take skin tone, age, body type, and (after a later case) gender from the photo, and to treat any conflicting description in the preset text as lower priority.

We verified this with A/B pairs on real user photos: same preset, same photo, lock on vs off. Without the lock, skin visibly darkened and the subject looked older. With the lock, skin tone and age matched the source photo and the scene itself was unaffected. As a side effect, the lock also reduced a category of moderation false-positives (the model flagging the output as suspicious content), because a bad identity mismatch triggers more false flags than a consistent one does.

The part that isn't obvious: this fix has limits

A global "lock everything to the photo" instruction breaks a different category of tool: anything that's supposed to change the person. Hairstyle try-on, hair color, beard try-on, aging filters, caricature, a few others. If you tell the model "hair strictly as in the photo" while also asking it to change the haircut, you get a model that just... doesn't change the haircut, because the lock instruction and the user's actual request are in direct conflict.

The fix there was narrower, not a blanket lock. For hair and beard tools specifically, the instruction became: lock face, age, skin tone, and gender to the photo, but say nothing about hair, length, or color, since changing exactly that is the entire point of the tool. We ship this today in a hairstyle try-on tool (upload a photo, try a cut without touching your actual hair), and the same narrower-lock principle applies to color and beard tools.

Takeaway

If you're building identity-preserving generation, the lock instruction isn't a single global switch, it's a per-tool decision: what part of the subject is supposed to stay fixed, and what part is the actual output you're generating. Getting that boundary wrong in either direction either breaks the identity or breaks the feature.

We build this inside Promtix, an AI photo and video studio, hairstyle try-on is one of the tools where this distinction matters most.

來源:DEV Community · dev.to