Text-to-3D
Transformers
Safetensors
English
deltaregion
feature-extraction
flame
3dmm
3d-face
face-shape-editing
text-guided-editing
cvae
avatar
gaussian-splatting
custom_code
Instructions to use a-canela/DeltaRegion with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use a-canela/DeltaRegion with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("a-canela/DeltaRegion", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload DeltaRegion (safetensors + remote code + model card)
Browse files- README.md +246 -0
- config.json +124 -0
- model.safetensors +3 -0
- modeling_deltaregion.py +436 -0
- special_tokens_map.json +107 -0
- spiece.model +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +112 -0
README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
- 3dmm
|
| 10 |
+
- 3d-face
|
| 11 |
+
- face-shape-editing
|
| 12 |
+
- text-guided-editing
|
| 13 |
+
- cvae
|
| 14 |
+
- avatar
|
| 15 |
+
- gaussian-splatting
|
| 16 |
+
- custom_code
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# DeltaRegion: text-guided, region-disentangled FLAME shape editing
|
| 20 |
+
|
| 21 |
+
**DeltaRegion** edits the identity shape of a [FLAME 2020](https://flame.is.tue.mpg.de/)
|
| 22 |
+
head model from a short natural-language prompt. You give it a source identity
|
| 23 |
+
$\beta_0 \in \mathbb{R}^{300}$ and a prompt such as *"make the nose long"*. It
|
| 24 |
+
returns an edited identity $\beta_1 = \beta_0 + \Delta\beta$ in a single
|
| 25 |
+
deterministic forward pass. The change stays inside the facial region named in
|
| 26 |
+
the prompt (face, nose, lips, ears, neck or eyes).
|
| 27 |
+
|
| 28 |
+
DeltaRegion is the shape-editing stage of **ManifoldSplat: Language-Guided Semantic
|
| 29 |
+
Shape Editing of 3D Gaussian Head Avatars** (GCPR 2026). There, the edited FLAME
|
| 30 |
+
identity drives the refinement of an animatable 3D Gaussian Splatting avatar.
|
| 31 |
+
Project page: <https://a-canela.github.io/manifoldsplat/>.
|
| 32 |
+
|
| 33 |
+
## Model details
|
| 34 |
+
|
| 35 |
+
| | |
|
| 36 |
+
|---|---|
|
| 37 |
+
| **Developed by** | Antonio Canela, Jordi Sànchez-Riera (UPC, IRI CSIC-UPC) |
|
| 38 |
+
| **Model type** | Conditional VAE (text + shape → FLAME shape delta) with a per-region gated latent |
|
| 39 |
+
| **Input** | English prompt + FLAME 2020 shape coefficients (300-D) |
|
| 40 |
+
| **Output** | Edited FLAME 2020 shape coefficients (300-D) and region probabilities |
|
| 41 |
+
| **Parameters** | 348.0 M in total: 341.2 M frozen Flan-T5-Large encoder + 6.8 M trained DeltaRegion heads |
|
| 42 |
+
| **Weights** | `model.safetensors` (fp32, 1.39 GB; the T5 encoder is bundled, so nothing else is downloaded) |
|
| 43 |
+
| **License** | CC BY-NC 4.0 (non-commercial; see [License](#license)) |
|
| 44 |
+
|
| 45 |
+
### Architecture
|
| 46 |
+
|
| 47 |
+
1. **Text encoder.** The prompt goes through a frozen
|
| 48 |
+
[Flan-T5-Large](https://huggingface.co/google/flan-t5-large) encoder
|
| 49 |
+
(1024-D tokens, max 128 tokens). It also produces a masked-mean sentence
|
| 50 |
+
embedding.
|
| 51 |
+
2. **Shape encoder.** An MLP ([512, 512], LayerNorm, GELU) embeds $\beta_0$
|
| 52 |
+
into a single 512-D token.
|
| 53 |
+
3. **Cross-attention fusion.** The shape token is the query and the projected
|
| 54 |
+
text tokens are the keys/values (8 heads). A residual connection and
|
| 55 |
+
LayerNorm follow.
|
| 56 |
+
4. **Region gate.** A softmax over the 6 regions, predicted from the sentence
|
| 57 |
+
embedding alone.
|
| 58 |
+
5. **Prior / posterior.** Diagonal Gaussians over
|
| 59 |
+
$z \in \mathbb{R}^{6 \times 8}$, one 8-D block per region. The posterior is
|
| 60 |
+
used only during training.
|
| 61 |
+
6. **Decoder.** Each latent block is multiplied by its gate value, concatenated
|
| 62 |
+
with the shape embedding and passed through an MLP ([768, 512, 512]), which
|
| 63 |
+
outputs $\Delta\beta \in \mathbb{R}^{300}$.
|
| 64 |
+
|
| 65 |
+
At inference the posterior is dropped and $z = s \cdot \mu_{prior}$ with
|
| 66 |
+
$s = 1.2$ (`config.inference_prior_scale`). You can change $s$ (the
|
| 67 |
+
`prior_scale` argument) to make the edit weaker or stronger.
|
| 68 |
+
|
| 69 |
+
## How to use
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
pip install torch transformers safetensors sentencepiece
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
```python
|
| 76 |
+
import torch
|
| 77 |
+
from transformers import AutoModel
|
| 78 |
+
|
| 79 |
+
# revision pins the release, so the downloaded weights and model code cannot change later
|
| 80 |
+
model = AutoModel.from_pretrained("a-canela/DeltaRegion", revision="v1.0", trust_remote_code=True).eval()
|
| 81 |
+
|
| 82 |
+
# 1) Edit the neutral (mean) FLAME identity
|
| 83 |
+
out = model.edit("make the nose long")
|
| 84 |
+
edited_betas = out.pred_shape # (1, 300) FLAME 2020 shape coefficients
|
| 85 |
+
print(model.region_probabilities(out.gate)) # [{'face': ..., 'nose': 0.99, ...}]
|
| 86 |
+
|
| 87 |
+
# 2) Edit your own identity (e.g. FLAME shape from MICA / a face tracker)
|
| 88 |
+
source_betas = torch.zeros(300) # replace with your subject's 300 shape coefficients
|
| 89 |
+
out = model.edit(
|
| 90 |
+
["make the lips thick", "make the ears very protruding"],
|
| 91 |
+
source_shape=source_betas, # (300,), (1, 300) or (B, 300)
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# 3) Control the edit strength continuously
|
| 95 |
+
weaker = model.edit("make the nose long", prior_scale=0.6)
|
| 96 |
+
stronger = model.edit("make the nose long", prior_scale=1.8)
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
You can also tokenize the prompt yourself and call the forward pass directly.
|
| 100 |
+
Pad to 128 tokens to reproduce the training inputs exactly:
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
from transformers import T5TokenizerFast
|
| 104 |
+
|
| 105 |
+
tokenizer = T5TokenizerFast.from_pretrained("a-canela/DeltaRegion", revision="v1.0")
|
| 106 |
+
tokens = tokenizer(["make the eyes wide-set"], padding="max_length", max_length=128,
|
| 107 |
+
truncation=True, return_tensors="pt")
|
| 108 |
+
with torch.no_grad():
|
| 109 |
+
out = model(tokens["input_ids"], tokens["attention_mask"], torch.zeros(1, 300))
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
The output `pred_shape` holds FLAME 2020 identity coefficients. Expression,
|
| 113 |
+
pose, eyelids and texture are not modified. To get a mesh, feed the
|
| 114 |
+
coefficients to a FLAME 2020 layer. The FLAME model files are not included
|
| 115 |
+
here: register and download them from <https://flame.is.tue.mpg.de/>.
|
| 116 |
+
FLAME fits with fewer than 300 shape coefficients should be zero-padded to 300.
|
| 117 |
+
|
| 118 |
+
### Prompting
|
| 119 |
+
|
| 120 |
+
The model learned prompts of the form **"make the {region} {edit}"**, plus a
|
| 121 |
+
few template variants such as *"give the {region} a {qualifier} {edit} shape"*
|
| 122 |
+
or *"change the {region} to be {qualifier} {edit}"*. Name the region explicitly:
|
| 123 |
+
the gate uses it to decide where the edit goes.
|
| 124 |
+
|
| 125 |
+
Training covered three edit magnitudes, each tied to a set of qualifiers:
|
| 126 |
+
|
| 127 |
+
| Training scale | Qualifiers |
|
| 128 |
+
|---|---|
|
| 129 |
+
| 0.5× | *subtly, slightly, a little, a bit, somewhat* |
|
| 130 |
+
| 1.0× | *(no qualifier)* |
|
| 131 |
+
| 1.5× | *very, significantly, much more* |
|
| 132 |
+
|
| 133 |
+
<details>
|
| 134 |
+
<summary><b>Edit prototypes seen in training (129 in total)</b></summary>
|
| 135 |
+
|
| 136 |
+
- **face (25):** big, small, wide, narrow, long, short, big forehead, small forehead, with chubby cheeks, with lean cheeks, with pronounced cheekbones, with a prominent / recessed / long / short / wide / narrow / cleft / pointed chin, with a wide / narrow / squared / rounded jaw, with the jaw deviated to the left / right
|
| 137 |
+
- **nose (43):** small, big, narrow, wide, short, long, narrow / wide / protruding / recessed at the radix, narrow / thick / protruding / recessed / deviated left / deviated right at the bridge, with a downturned / upturned / recessed / protruding tip, small / big / narrow / wide / deviated left / deviated right at the base, with downturned / upturned / flared / narrow nostrils, aquiline, hawk-like, Greek, flat, saddle-shaped, wavy in profile, linearly deviated to the left / right, C-shaped crooked to the left / right, S-shaped crooked to the left / right, and one composite prototype that will be removed in the next release
|
| 138 |
+
- **lips (26):** small, big, wide, narrow, with a thin / thick upper lip, with a thin / thick lower lip, with thin / thick lips, protruding, recessed, with a protruding / recessed lower / upper lip, with upturned / downturned corners, with the left / right corner raised / lowered, horizontally / vertically left / right asymmetric
|
| 139 |
+
- **ears (14):** small, big, short, long, narrow, wide, attached lobe, detached lobe, protruding, flat, pointed top, rounded top, left protruding, right protruding
|
| 140 |
+
- **neck (6):** thick, thin, long, short, with double chin, with prominent adam's apple
|
| 141 |
+
- **eyes (15):** small, big, wide, narrow, vertically tall, almond-shaped, deep-set, prominent, close-set, wide-set, upturned, downturned, with a raised / low / prominent brow ridge
|
| 142 |
+
|
| 143 |
+
</details>
|
| 144 |
+
|
| 145 |
+
## Training data
|
| 146 |
+
|
| 147 |
+
No public corpus pairs prompts with identity-preserving FLAME shape deltas, so
|
| 148 |
+
the training set is synthetic:
|
| 149 |
+
|
| 150 |
+
- **Source identities:** 300 FLAME 2020 identities fitted by MICA to the
|
| 151 |
+
Liverpool-York Head Model (LYHM) dataset.
|
| 152 |
+
- **Edit prototypes:** 129 hand-authored edits over 6 regions. Each one is a
|
| 153 |
+
sparse set of FLAME vertex indices with 3D displacement vectors and a
|
| 154 |
+
canonical prompt fragment.
|
| 155 |
+
- **Targets:** for every (subject, edit, scale ∈ {0.5, 1.0, 1.5}) tuple,
|
| 156 |
+
$\Delta\beta$ comes from an iterative projection onto the FLAME shape basis
|
| 157 |
+
(Adam, 1500 steps, lr 1e-2, ℓ2 weight 1e-6). An outside-region penalty
|
| 158 |
+
(weight 1e2) stops the deformation from leaking into other regions.
|
| 159 |
+
- **Prompts:** 5 template-based variants per tuple, with scale-dependent
|
| 160 |
+
qualifiers. This gives **580,500 triplets** $(\beta_0, t, \beta_1)$:
|
| 161 |
+
300 × 129 × 3 × 5.
|
| 162 |
+
- **Split:** 85% train / 15% validation, random over triplets with seed 42.
|
| 163 |
+
Validation shares identities and edit prototypes with training, so the
|
| 164 |
+
validation loss does not measure generalisation to unseen identities or edits.
|
| 165 |
+
|
| 166 |
+
The training data, LYHM and FLAME are **not** redistributed with this model.
|
| 167 |
+
|
| 168 |
+
## Training procedure
|
| 169 |
+
|
| 170 |
+
- **Objective:** region-masked vertex losses inside the edited region
|
| 171 |
+
($\lambda = 5\cdot10^5$) and outside it ($\lambda = 5\cdot10^5$),
|
| 172 |
+
ℓ2 on shape parameters ($\lambda = 10$), gate cross-entropy
|
| 173 |
+
($\lambda = 10$) and a free-bits KL term ($\lambda = 0.05$, free bits 0.03,
|
| 174 |
+
10-epoch linear warm-up).
|
| 175 |
+
- **Optimisation:** AdamW (lr 1e-4, weight decay 0.01, gradient clipping 1.0),
|
| 176 |
+
batch size 256, 100 epochs on a single NVIDIA RTX 5090. Training took about
|
| 177 |
+
40 h; data generation took about 70 h.
|
| 178 |
+
- **Checkpoint:** best validation loss, reached at epoch 71 of 100. Only the
|
| 179 |
+
DeltaRegion heads were trained; the Flan-T5 encoder stayed frozen.
|
| 180 |
+
- **Precision:** fp32.
|
| 181 |
+
|
| 182 |
+
## Limitations
|
| 183 |
+
|
| 184 |
+
- **Bounded edit space.** The model only knows the 129 prototypes listed above
|
| 185 |
+
and their interpolations. Structural changes outside that set are not
|
| 186 |
+
produced reliably, and prompts far from the training phrasing may be
|
| 187 |
+
mapped to the wrong region or produce weak edits. Check `gate` /
|
| 188 |
+
`region_probabilities` to see which region was selected.
|
| 189 |
+
- **One region per prompt.** The gate is trained with single-region labels.
|
| 190 |
+
Compound prompts ("big nose and thin lips") are not supported; apply the
|
| 191 |
+
edits one after another instead.
|
| 192 |
+
- **Shape only.** Only FLAME identity geometry changes. Hair, accessories,
|
| 193 |
+
skin, eye colour and texture are not modelled, and expression/pose
|
| 194 |
+
coefficients are untouched.
|
| 195 |
+
- **Magnitude.** Edit strength was only supervised at 0.5×, 1.0× and 1.5×.
|
| 196 |
+
Values of `prior_scale` far outside about [0.5, 2] may produce implausible
|
| 197 |
+
shapes.
|
| 198 |
+
- **Source distribution.** Training identities are MICA fits to LYHM scans.
|
| 199 |
+
Identities far from that distribution, or from other FLAME fitting
|
| 200 |
+
pipelines with a different coefficient distribution, may behave worse.
|
| 201 |
+
- **English only**, with short imperative prompts.
|
| 202 |
+
|
| 203 |
+
## Bias, risks and ethical considerations
|
| 204 |
+
|
| 205 |
+
- **Demographic coverage.** LYHM was collected in the United Kingdom and does
|
| 206 |
+
not represent the global population evenly. The model has seen a limited
|
| 207 |
+
variety of age, ethnicity and face morphology, and may perform worse on
|
| 208 |
+
under-represented groups.
|
| 209 |
+
- **Language bias.** Words such as *"big"* or *"prominent"* were mapped to
|
| 210 |
+
shapes chosen by the authors. They are not objective or culturally neutral.
|
| 211 |
+
- **Misuse.** Editing a real person's facial geometry can be used to create
|
| 212 |
+
misleading or non-consensual depictions. Only edit identities of people who
|
| 213 |
+
have consented, and disclose that avatars are synthetic.
|
| 214 |
+
- **No biometric use.** The model is not intended for face recognition,
|
| 215 |
+
identity verification, or inferring any personal attribute.
|
| 216 |
+
|
| 217 |
+
## License
|
| 218 |
+
|
| 219 |
+
The DeltaRegion weights and code are released under
|
| 220 |
+
**[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)**
|
| 221 |
+
(non-commercial use only), because the model is derived from:
|
| 222 |
+
|
| 223 |
+
- **FLAME 2020** (Max Planck Institute for Intelligent Systems): non-commercial
|
| 224 |
+
scientific research licence. You need your own FLAME licence to turn the
|
| 225 |
+
outputs into meshes.
|
| 226 |
+
- **LYHM** identities, fitted with MICA: academic, non-commercial use.
|
| 227 |
+
- **Flan-T5-Large** encoder weights and tokenizer from
|
| 228 |
+
[google/flan-t5-large](https://huggingface.co/google/flan-t5-large):
|
| 229 |
+
Apache-2.0. They are bundled here unchanged.
|
| 230 |
+
|
| 231 |
+
Make sure your use also complies with the FLAME and LYHM licence terms.
|
| 232 |
+
|
| 233 |
+
## Citation
|
| 234 |
+
|
| 235 |
+
```bibtex
|
| 236 |
+
@inproceedings{canela2026manifoldsplat,
|
| 237 |
+
title = {ManifoldSplat: Language-Guided Semantic Shape Editing of 3D Gaussian Head Avatars},
|
| 238 |
+
author = {Canela, Antonio and Sanchez-Riera, Jordi},
|
| 239 |
+
booktitle = {DAGM German Conference on Pattern Recognition (GCPR)},
|
| 240 |
+
year = {2026}
|
| 241 |
+
}
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
Please also cite FLAME (Li et al., *SIGGRAPH Asia* 2017), MICA (Zielonka et
|
| 245 |
+
al., *ECCV* 2022), LYHM (Dai et al., *IJCV* 2020) and Flan-T5 (Chung et al.,
|
| 246 |
+
*JMLR* 2024).
|
config.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"DeltaRegionModel"
|
| 4 |
+
],
|
| 5 |
+
"attribute_names": [
|
| 6 |
+
"face",
|
| 7 |
+
"nose",
|
| 8 |
+
"lips",
|
| 9 |
+
"ears",
|
| 10 |
+
"neck",
|
| 11 |
+
"eyes"
|
| 12 |
+
],
|
| 13 |
+
"auto_map": {
|
| 14 |
+
"AutoConfig": "modeling_deltaregion.DeltaRegionConfig",
|
| 15 |
+
"AutoModel": "modeling_deltaregion.DeltaRegionModel"
|
| 16 |
+
},
|
| 17 |
+
"cross_attention": {
|
| 18 |
+
"d_model": 512,
|
| 19 |
+
"dropout": 0.1,
|
| 20 |
+
"num_heads": 8
|
| 21 |
+
},
|
| 22 |
+
"delta_decoder": {
|
| 23 |
+
"dropout": 0.15,
|
| 24 |
+
"final_activation": null,
|
| 25 |
+
"hidden_dims": [
|
| 26 |
+
768,
|
| 27 |
+
512,
|
| 28 |
+
512
|
| 29 |
+
],
|
| 30 |
+
"use_layer_norm": false
|
| 31 |
+
},
|
| 32 |
+
"dims_per_attribute": 8,
|
| 33 |
+
"dtype": "float32",
|
| 34 |
+
"fused_dropout_rate": 0.3,
|
| 35 |
+
"gate_net": {
|
| 36 |
+
"dropout": 0.15,
|
| 37 |
+
"final_activation": null,
|
| 38 |
+
"hidden_dims": [
|
| 39 |
+
512
|
| 40 |
+
],
|
| 41 |
+
"use_layer_norm": false
|
| 42 |
+
},
|
| 43 |
+
"inference_prior_scale": 1.2,
|
| 44 |
+
"max_text_length": 128,
|
| 45 |
+
"model_type": "deltaregion",
|
| 46 |
+
"posterior_net": {
|
| 47 |
+
"delta_encoder_hidden_dims": [
|
| 48 |
+
512,
|
| 49 |
+
512
|
| 50 |
+
],
|
| 51 |
+
"dropout": 0.15,
|
| 52 |
+
"final_activation": null,
|
| 53 |
+
"hidden_dims": [
|
| 54 |
+
768,
|
| 55 |
+
512
|
| 56 |
+
],
|
| 57 |
+
"use_layer_norm": true
|
| 58 |
+
},
|
| 59 |
+
"prior_net": {
|
| 60 |
+
"dropout": 0.15,
|
| 61 |
+
"final_activation": null,
|
| 62 |
+
"hidden_dims": [
|
| 63 |
+
768,
|
| 64 |
+
512
|
| 65 |
+
],
|
| 66 |
+
"use_layer_norm": true
|
| 67 |
+
},
|
| 68 |
+
"shape_dim": 300,
|
| 69 |
+
"shape_encoder": {
|
| 70 |
+
"dropout": 0.15,
|
| 71 |
+
"final_activation": null,
|
| 72 |
+
"hidden_dims": [
|
| 73 |
+
512,
|
| 74 |
+
512
|
| 75 |
+
],
|
| 76 |
+
"use_layer_norm": true
|
| 77 |
+
},
|
| 78 |
+
"t5_config": {
|
| 79 |
+
"chunk_size_feed_forward": 0,
|
| 80 |
+
"classifier_dropout": 0.0,
|
| 81 |
+
"d_ff": 2816,
|
| 82 |
+
"d_kv": 64,
|
| 83 |
+
"d_model": 1024,
|
| 84 |
+
"decoder_start_token_id": 0,
|
| 85 |
+
"dense_act_fn": "gelu_new",
|
| 86 |
+
"dropout_rate": 0.1,
|
| 87 |
+
"eos_token_id": 1,
|
| 88 |
+
"feed_forward_proj": "gated-gelu",
|
| 89 |
+
"id2label": {
|
| 90 |
+
"0": "LABEL_0",
|
| 91 |
+
"1": "LABEL_1"
|
| 92 |
+
},
|
| 93 |
+
"initializer_factor": 1.0,
|
| 94 |
+
"is_decoder": false,
|
| 95 |
+
"is_encoder_decoder": true,
|
| 96 |
+
"is_gated_act": true,
|
| 97 |
+
"label2id": {
|
| 98 |
+
"LABEL_0": 0,
|
| 99 |
+
"LABEL_1": 1
|
| 100 |
+
},
|
| 101 |
+
"layer_norm_epsilon": 1e-06,
|
| 102 |
+
"model_type": "t5",
|
| 103 |
+
"n_positions": 512,
|
| 104 |
+
"num_decoder_layers": 24,
|
| 105 |
+
"num_heads": 16,
|
| 106 |
+
"num_layers": 24,
|
| 107 |
+
"output_attentions": false,
|
| 108 |
+
"output_hidden_states": false,
|
| 109 |
+
"output_past": true,
|
| 110 |
+
"pad_token_id": 0,
|
| 111 |
+
"problem_type": null,
|
| 112 |
+
"relative_attention_max_distance": 128,
|
| 113 |
+
"relative_attention_num_buckets": 32,
|
| 114 |
+
"return_dict": true,
|
| 115 |
+
"scale_decoder_outputs": false,
|
| 116 |
+
"tie_word_embeddings": true,
|
| 117 |
+
"use_cache": true,
|
| 118 |
+
"vocab_size": 32128
|
| 119 |
+
},
|
| 120 |
+
"text_dim": 1024,
|
| 121 |
+
"text_model_name": "google/flan-t5-large",
|
| 122 |
+
"tie_word_embeddings": false,
|
| 123 |
+
"transformers_version": "5.23.0"
|
| 124 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fcbc42b8acf28b2b0456f958abe6ccdaefebe1159bce3932fbe3e073dbc7fe5d
|
| 3 |
+
size 1392081896
|
modeling_deltaregion.py
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
| 3 |
+
#
|
| 4 |
+
# Licensed under the Creative Commons Attribution-NonCommercial 4.0
|
| 5 |
+
# International License (CC BY-NC 4.0). See the model card for details.
|
| 6 |
+
"""DeltaRegion: text-guided, region-disentangled FLAME shape editor.
|
| 7 |
+
|
| 8 |
+
DeltaRegion is a conditional VAE that maps a natural-language edit prompt and a
|
| 9 |
+
source FLAME 2020 identity (300 shape coefficients) to an edited identity
|
| 10 |
+
``beta_1 = beta_0 + delta``. The prompt is encoded by a frozen Flan-T5-Large
|
| 11 |
+
encoder, fused with the source shape via cross-attention, and a per-region gate
|
| 12 |
+
restricts the edit to one of six facial regions (face, nose, lips, ears, neck,
|
| 13 |
+
eyes).
|
| 14 |
+
|
| 15 |
+
This file is self-contained: it only depends on ``torch`` and ``transformers``.
|
| 16 |
+
|
| 17 |
+
Usage::
|
| 18 |
+
|
| 19 |
+
from transformers import AutoModel
|
| 20 |
+
|
| 21 |
+
model = AutoModel.from_pretrained("a-canela/DeltaRegion", trust_remote_code=True)
|
| 22 |
+
out = model.edit("make the nose long") # neutral source identity
|
| 23 |
+
edited_betas = out.pred_shape # (1, 300)
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
from dataclasses import dataclass
|
| 27 |
+
from typing import Optional, Sequence, Union
|
| 28 |
+
|
| 29 |
+
import torch
|
| 30 |
+
import torch.nn as nn
|
| 31 |
+
import torch.nn.functional as F
|
| 32 |
+
from transformers import PretrainedConfig, PreTrainedModel, T5Config, T5EncoderModel
|
| 33 |
+
from transformers.utils import ModelOutput
|
| 34 |
+
|
| 35 |
+
DEFAULT_ATTRIBUTE_NAMES = ("face", "nose", "lips", "ears", "neck", "eyes")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class DeltaRegionConfig(PretrainedConfig):
|
| 39 |
+
r"""Configuration for :class:`DeltaRegionModel`.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
attribute_names (`list[str]`): Facial regions, in latent-block / gate order.
|
| 43 |
+
dims_per_attribute (`int`): Latent dimensions per region block.
|
| 44 |
+
inference_prior_scale (`float`): Prior-mean scale ``s`` used at inference
|
| 45 |
+
(``z = s * mu_prior``). Acts as a continuous edit-strength knob.
|
| 46 |
+
fused_dropout_rate (`float`): Dropout applied to the identity context fed
|
| 47 |
+
to the decoder (only active in training mode).
|
| 48 |
+
text_model_name (`str`): Hub id of the text encoder the weights come from
|
| 49 |
+
(informational; weights are bundled in this repository).
|
| 50 |
+
text_dim (`int`): Hidden size of the text encoder.
|
| 51 |
+
max_text_length (`int`): Tokenizer max length used in training (padding to
|
| 52 |
+
this length reproduces training-time inputs exactly).
|
| 53 |
+
t5_config (`dict`): Serialized ``T5Config`` of the frozen text encoder.
|
| 54 |
+
shape_dim (`int`): Number of FLAME shape coefficients.
|
| 55 |
+
shape_encoder, cross_attention, gate_net, prior_net, posterior_net,
|
| 56 |
+
delta_decoder (`dict`): Sub-network hyper-parameters.
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
model_type = "deltaregion"
|
| 60 |
+
|
| 61 |
+
def __init__(
|
| 62 |
+
self,
|
| 63 |
+
attribute_names: Optional[Sequence[str]] = None,
|
| 64 |
+
dims_per_attribute: int = 8,
|
| 65 |
+
inference_prior_scale: float = 1.2,
|
| 66 |
+
fused_dropout_rate: float = 0.3,
|
| 67 |
+
text_model_name: str = "google/flan-t5-large",
|
| 68 |
+
text_dim: int = 1024,
|
| 69 |
+
max_text_length: int = 128,
|
| 70 |
+
t5_config: Optional[dict] = None,
|
| 71 |
+
shape_dim: int = 300,
|
| 72 |
+
shape_encoder: Optional[dict] = None,
|
| 73 |
+
cross_attention: Optional[dict] = None,
|
| 74 |
+
gate_net: Optional[dict] = None,
|
| 75 |
+
prior_net: Optional[dict] = None,
|
| 76 |
+
posterior_net: Optional[dict] = None,
|
| 77 |
+
delta_decoder: Optional[dict] = None,
|
| 78 |
+
**kwargs,
|
| 79 |
+
):
|
| 80 |
+
kwargs.setdefault("tie_word_embeddings", False)
|
| 81 |
+
super().__init__(**kwargs)
|
| 82 |
+
self.attribute_names = list(attribute_names or DEFAULT_ATTRIBUTE_NAMES)
|
| 83 |
+
self.dims_per_attribute = dims_per_attribute
|
| 84 |
+
self.inference_prior_scale = inference_prior_scale
|
| 85 |
+
self.fused_dropout_rate = fused_dropout_rate
|
| 86 |
+
self.text_model_name = text_model_name
|
| 87 |
+
self.text_dim = text_dim
|
| 88 |
+
self.max_text_length = max_text_length
|
| 89 |
+
self.t5_config = t5_config if t5_config is not None else {}
|
| 90 |
+
self.shape_dim = shape_dim
|
| 91 |
+
self.shape_encoder = shape_encoder or {
|
| 92 |
+
"hidden_dims": [512, 512],
|
| 93 |
+
"dropout": 0.15,
|
| 94 |
+
"use_layer_norm": True,
|
| 95 |
+
"final_activation": None,
|
| 96 |
+
}
|
| 97 |
+
# NOTE: the attention width is the last shape-encoder hidden size;
|
| 98 |
+
# ``cross_attention["d_model"]`` is kept for reference only.
|
| 99 |
+
self.cross_attention = cross_attention or {"d_model": 512, "num_heads": 8, "dropout": 0.1}
|
| 100 |
+
self.gate_net = gate_net or {
|
| 101 |
+
"hidden_dims": [512],
|
| 102 |
+
"dropout": 0.15,
|
| 103 |
+
"use_layer_norm": False,
|
| 104 |
+
"final_activation": None,
|
| 105 |
+
}
|
| 106 |
+
self.prior_net = prior_net or {
|
| 107 |
+
"hidden_dims": [768, 512],
|
| 108 |
+
"dropout": 0.15,
|
| 109 |
+
"use_layer_norm": True,
|
| 110 |
+
"final_activation": None,
|
| 111 |
+
}
|
| 112 |
+
self.posterior_net = posterior_net or {
|
| 113 |
+
"delta_encoder_hidden_dims": [512, 512],
|
| 114 |
+
"hidden_dims": [768, 512],
|
| 115 |
+
"dropout": 0.15,
|
| 116 |
+
"use_layer_norm": True,
|
| 117 |
+
"final_activation": None,
|
| 118 |
+
}
|
| 119 |
+
self.delta_decoder = delta_decoder or {
|
| 120 |
+
"hidden_dims": [768, 512, 512],
|
| 121 |
+
"dropout": 0.15,
|
| 122 |
+
"use_layer_norm": False,
|
| 123 |
+
"final_activation": None,
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
@classmethod
|
| 127 |
+
def from_training_config(cls, model_config: dict, t5_config: dict, **kwargs) -> "DeltaRegionConfig":
|
| 128 |
+
"""Build from the ``"model"`` section of the original training config."""
|
| 129 |
+
text_cfg = model_config["text_encoder"]
|
| 130 |
+
return cls(
|
| 131 |
+
dims_per_attribute=model_config["dims_per_attribute"],
|
| 132 |
+
inference_prior_scale=model_config.get("inference_prior_scale", 1.0),
|
| 133 |
+
fused_dropout_rate=model_config.get("fused_dropout_rate", 0.0),
|
| 134 |
+
text_model_name=text_cfg["model_name"],
|
| 135 |
+
text_dim=text_cfg["text_dim"],
|
| 136 |
+
max_text_length=text_cfg.get("max_length", 128),
|
| 137 |
+
t5_config=t5_config,
|
| 138 |
+
shape_dim=model_config["shape_encoder"]["shape_dim"],
|
| 139 |
+
shape_encoder={k: v for k, v in model_config["shape_encoder"].items() if k != "shape_dim"},
|
| 140 |
+
cross_attention=model_config["cross_attention"],
|
| 141 |
+
gate_net=model_config["gate_net"],
|
| 142 |
+
prior_net=model_config["prior_net"],
|
| 143 |
+
posterior_net=model_config["posterior_net"],
|
| 144 |
+
delta_decoder=model_config["delta_decoder"],
|
| 145 |
+
**kwargs,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@dataclass
|
| 150 |
+
class DeltaRegionOutput(ModelOutput):
|
| 151 |
+
"""Outputs of :class:`DeltaRegionModel`.
|
| 152 |
+
|
| 153 |
+
Shapes use ``B`` = batch size, ``K`` = number of regions, ``d`` = dims per
|
| 154 |
+
region and ``S`` = number of FLAME shape coefficients (300).
|
| 155 |
+
``mu_post``/``logvar_post`` are ``None`` at inference (no ``target_shape``).
|
| 156 |
+
"""
|
| 157 |
+
|
| 158 |
+
pred_shape: Optional[torch.FloatTensor] = None # (B, S) edited shape beta_0 + delta
|
| 159 |
+
delta: Optional[torch.FloatTensor] = None # (B, S)
|
| 160 |
+
gate: Optional[torch.FloatTensor] = None # (B, K) softmax over regions
|
| 161 |
+
gate_logits: Optional[torch.FloatTensor] = None # (B, K)
|
| 162 |
+
mu_prior: Optional[torch.FloatTensor] = None # (B, K*d)
|
| 163 |
+
logvar_prior: Optional[torch.FloatTensor] = None # (B, K*d)
|
| 164 |
+
mu_post: Optional[torch.FloatTensor] = None # (B, K*d)
|
| 165 |
+
logvar_post: Optional[torch.FloatTensor] = None # (B, K*d)
|
| 166 |
+
z: Optional[torch.FloatTensor] = None # (B, K*d)
|
| 167 |
+
z_gated: Optional[torch.FloatTensor] = None # (B, K, d)
|
| 168 |
+
fused: Optional[torch.FloatTensor] = None # (B, D) fused text-shape embedding
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _build_mlp(
|
| 172 |
+
input_dim: int,
|
| 173 |
+
hidden_dims: Sequence[int],
|
| 174 |
+
output_dim: Optional[int],
|
| 175 |
+
dropout: float,
|
| 176 |
+
use_layer_norm: bool = False,
|
| 177 |
+
final_activation: Optional[str] = None,
|
| 178 |
+
) -> nn.Sequential:
|
| 179 |
+
# Layer order must stay identical to training so state-dict indices match.
|
| 180 |
+
layers = []
|
| 181 |
+
prev_dim = input_dim
|
| 182 |
+
for hidden_dim in hidden_dims:
|
| 183 |
+
layers.append(nn.Linear(prev_dim, hidden_dim))
|
| 184 |
+
if use_layer_norm:
|
| 185 |
+
layers.append(nn.LayerNorm(hidden_dim))
|
| 186 |
+
layers.append(nn.GELU())
|
| 187 |
+
layers.append(nn.Dropout(dropout))
|
| 188 |
+
prev_dim = hidden_dim
|
| 189 |
+
if output_dim is not None:
|
| 190 |
+
layers.append(nn.Linear(prev_dim, output_dim))
|
| 191 |
+
if final_activation is not None:
|
| 192 |
+
layers.append(getattr(nn, final_activation)())
|
| 193 |
+
return nn.Sequential(*layers)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class DeltaRegionPreTrainedModel(PreTrainedModel):
|
| 197 |
+
config_class = DeltaRegionConfig
|
| 198 |
+
base_model_prefix = "deltaregion"
|
| 199 |
+
main_input_name = "input_ids"
|
| 200 |
+
supports_gradient_checkpointing = False
|
| 201 |
+
|
| 202 |
+
def _init_weights(self, module):
|
| 203 |
+
# Only the DeltaRegion heads are initialised here; the T5 encoder keeps
|
| 204 |
+
# its own initialisation. All weights are overwritten when loading.
|
| 205 |
+
if isinstance(module, (nn.Linear, nn.LayerNorm)):
|
| 206 |
+
module.reset_parameters()
|
| 207 |
+
elif isinstance(module, nn.MultiheadAttention):
|
| 208 |
+
module._reset_parameters()
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
class DeltaRegionModel(DeltaRegionPreTrainedModel):
|
| 212 |
+
"""Text-guided CVAE FLAME shape editor with per-region gated latent space."""
|
| 213 |
+
|
| 214 |
+
def __init__(self, config: DeltaRegionConfig):
|
| 215 |
+
super().__init__(config)
|
| 216 |
+
|
| 217 |
+
self.attribute_names = list(config.attribute_names)
|
| 218 |
+
self.num_attributes = len(self.attribute_names)
|
| 219 |
+
self.dims_per_attribute = config.dims_per_attribute
|
| 220 |
+
self.latent_dim = self.num_attributes * self.dims_per_attribute
|
| 221 |
+
self.inference_prior_scale = config.inference_prior_scale
|
| 222 |
+
|
| 223 |
+
# Frozen text encoder (Flan-T5-Large encoder, weights bundled).
|
| 224 |
+
self.text_encoder = T5EncoderModel(T5Config(**config.t5_config))
|
| 225 |
+
self.text_encoder.requires_grad_(False)
|
| 226 |
+
text_dim = config.text_dim
|
| 227 |
+
shape_dim = config.shape_dim
|
| 228 |
+
|
| 229 |
+
se = config.shape_encoder
|
| 230 |
+
self.shape_encoder = _build_mlp(
|
| 231 |
+
shape_dim, se["hidden_dims"], None, se["dropout"], se["use_layer_norm"], se["final_activation"]
|
| 232 |
+
)
|
| 233 |
+
d_model = se["hidden_dims"][-1]
|
| 234 |
+
|
| 235 |
+
ca = config.cross_attention
|
| 236 |
+
self.text_proj = nn.Linear(text_dim, d_model)
|
| 237 |
+
self.cross_attn = nn.MultiheadAttention(
|
| 238 |
+
embed_dim=d_model, num_heads=ca["num_heads"], dropout=ca["dropout"], batch_first=True
|
| 239 |
+
)
|
| 240 |
+
self.cross_attn_norm = nn.LayerNorm(d_model)
|
| 241 |
+
|
| 242 |
+
gn = config.gate_net
|
| 243 |
+
self.gate_text_proj = nn.Linear(text_dim, d_model)
|
| 244 |
+
self.gate_net = _build_mlp(
|
| 245 |
+
d_model, gn["hidden_dims"], self.num_attributes, gn["dropout"], gn["use_layer_norm"], gn["final_activation"]
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
pn = config.prior_net
|
| 249 |
+
self.prior_net = _build_mlp(
|
| 250 |
+
d_model, pn["hidden_dims"], self.latent_dim * 2, pn["dropout"], pn["use_layer_norm"], pn["final_activation"]
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
po = config.posterior_net
|
| 254 |
+
self.delta_encoder = _build_mlp(
|
| 255 |
+
shape_dim,
|
| 256 |
+
po["delta_encoder_hidden_dims"],
|
| 257 |
+
d_model,
|
| 258 |
+
po["dropout"],
|
| 259 |
+
po["use_layer_norm"],
|
| 260 |
+
po["final_activation"],
|
| 261 |
+
)
|
| 262 |
+
self.posterior_net = _build_mlp(
|
| 263 |
+
d_model * 2, po["hidden_dims"], self.latent_dim * 2, po["dropout"], po["use_layer_norm"], po["final_activation"]
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
self.fused_dropout = nn.Dropout(config.fused_dropout_rate) if config.fused_dropout_rate > 0 else None
|
| 267 |
+
|
| 268 |
+
dd = config.delta_decoder
|
| 269 |
+
self.delta_decoder = _build_mlp(
|
| 270 |
+
self.latent_dim + d_model,
|
| 271 |
+
dd["hidden_dims"],
|
| 272 |
+
shape_dim,
|
| 273 |
+
dd["dropout"],
|
| 274 |
+
dd["use_layer_norm"],
|
| 275 |
+
dd["final_activation"],
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
self._tokenizer = None
|
| 279 |
+
self.post_init()
|
| 280 |
+
|
| 281 |
+
@staticmethod
|
| 282 |
+
def reparameterize(mu: torch.Tensor, logvar: torch.Tensor) -> torch.Tensor:
|
| 283 |
+
std = torch.exp(0.5 * logvar)
|
| 284 |
+
eps = torch.randn_like(std)
|
| 285 |
+
return mu + std * eps
|
| 286 |
+
|
| 287 |
+
def forward(
|
| 288 |
+
self,
|
| 289 |
+
input_ids: torch.LongTensor,
|
| 290 |
+
attention_mask: torch.LongTensor,
|
| 291 |
+
source_shape: torch.FloatTensor,
|
| 292 |
+
target_shape: Optional[torch.FloatTensor] = None,
|
| 293 |
+
prior_scale: Optional[float] = None,
|
| 294 |
+
**kwargs,
|
| 295 |
+
) -> DeltaRegionOutput:
|
| 296 |
+
"""
|
| 297 |
+
Args:
|
| 298 |
+
input_ids: Flan-T5 token ids ``(B, L)``.
|
| 299 |
+
attention_mask: Token mask ``(B, L)``.
|
| 300 |
+
source_shape: Source FLAME shape coefficients ``(B, 300)``.
|
| 301 |
+
target_shape: Target shape ``(B, 300)``; training only (posterior path).
|
| 302 |
+
prior_scale: Overrides ``config.inference_prior_scale`` at inference.
|
| 303 |
+
"""
|
| 304 |
+
with torch.no_grad():
|
| 305 |
+
text_out = self.text_encoder(input_ids=input_ids, attention_mask=attention_mask)
|
| 306 |
+
text_embed = text_out.last_hidden_state # (B, L, text_dim)
|
| 307 |
+
|
| 308 |
+
mask = attention_mask.unsqueeze(-1).to(text_embed.dtype)
|
| 309 |
+
text_global = (text_embed * mask).sum(1) / mask.sum(1).clamp(min=1)
|
| 310 |
+
|
| 311 |
+
shape_embed = self.shape_encoder(source_shape) # (B, D)
|
| 312 |
+
|
| 313 |
+
text_kv = self.text_proj(text_embed)
|
| 314 |
+
attn_out, _ = self.cross_attn(
|
| 315 |
+
query=shape_embed.unsqueeze(1),
|
| 316 |
+
key=text_kv,
|
| 317 |
+
value=text_kv,
|
| 318 |
+
key_padding_mask=~attention_mask.bool(),
|
| 319 |
+
)
|
| 320 |
+
fused = self.cross_attn_norm(attn_out.squeeze(1) + shape_embed)
|
| 321 |
+
|
| 322 |
+
gate_logits = self.gate_net(self.gate_text_proj(text_global)) # (B, K)
|
| 323 |
+
gate = F.softmax(gate_logits, dim=-1)
|
| 324 |
+
|
| 325 |
+
mu_prior, logvar_prior = self.prior_net(fused).chunk(2, dim=-1)
|
| 326 |
+
|
| 327 |
+
if target_shape is not None:
|
| 328 |
+
delta_embed = self.delta_encoder(target_shape - source_shape)
|
| 329 |
+
mu_post, logvar_post = self.posterior_net(torch.cat([fused, delta_embed], dim=-1)).chunk(2, dim=-1)
|
| 330 |
+
z = self.reparameterize(mu_post, logvar_post)
|
| 331 |
+
else:
|
| 332 |
+
mu_post = logvar_post = None
|
| 333 |
+
scale = self.inference_prior_scale if prior_scale is None else prior_scale
|
| 334 |
+
z = mu_prior * scale
|
| 335 |
+
|
| 336 |
+
z_gated = z.view(-1, self.num_attributes, self.dims_per_attribute) * gate.unsqueeze(-1)
|
| 337 |
+
z_gated_flat = z_gated.view(-1, self.latent_dim)
|
| 338 |
+
|
| 339 |
+
# The decoder only sees the identity embedding (no text), so every edit
|
| 340 |
+
# must flow through the gated latent z.
|
| 341 |
+
identity_ctx = shape_embed
|
| 342 |
+
if self.fused_dropout is not None:
|
| 343 |
+
identity_ctx = self.fused_dropout(identity_ctx)
|
| 344 |
+
delta = self.delta_decoder(torch.cat([z_gated_flat, identity_ctx], dim=-1))
|
| 345 |
+
|
| 346 |
+
return DeltaRegionOutput(
|
| 347 |
+
pred_shape=source_shape + delta,
|
| 348 |
+
delta=delta,
|
| 349 |
+
gate=gate,
|
| 350 |
+
gate_logits=gate_logits,
|
| 351 |
+
mu_prior=mu_prior,
|
| 352 |
+
logvar_prior=logvar_prior,
|
| 353 |
+
mu_post=mu_post,
|
| 354 |
+
logvar_post=logvar_post,
|
| 355 |
+
z=z,
|
| 356 |
+
z_gated=z_gated,
|
| 357 |
+
fused=fused,
|
| 358 |
+
)
|
| 359 |
+
|
| 360 |
+
def get_tokenizer(self):
|
| 361 |
+
"""Lazily load the tokenizer shipped with the checkpoint (Flan-T5)."""
|
| 362 |
+
if self._tokenizer is None:
|
| 363 |
+
from transformers import T5TokenizerFast
|
| 364 |
+
|
| 365 |
+
self._tokenizer = T5TokenizerFast.from_pretrained(self.name_or_path or self.config.text_model_name)
|
| 366 |
+
return self._tokenizer
|
| 367 |
+
|
| 368 |
+
def tokenize(self, prompts: Union[str, Sequence[str]], tokenizer=None):
|
| 369 |
+
"""Tokenize exactly as in training (pad to ``max_text_length``, truncate)."""
|
| 370 |
+
if isinstance(prompts, str):
|
| 371 |
+
prompts = [prompts]
|
| 372 |
+
tokenizer = tokenizer or self.get_tokenizer()
|
| 373 |
+
return tokenizer(
|
| 374 |
+
list(prompts),
|
| 375 |
+
padding="max_length",
|
| 376 |
+
max_length=self.config.max_text_length,
|
| 377 |
+
truncation=True,
|
| 378 |
+
return_tensors="pt",
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
@torch.no_grad()
|
| 382 |
+
def edit(
|
| 383 |
+
self,
|
| 384 |
+
prompts: Union[str, Sequence[str]],
|
| 385 |
+
source_shape: Optional[torch.Tensor] = None,
|
| 386 |
+
prior_scale: Optional[float] = None,
|
| 387 |
+
tokenizer=None,
|
| 388 |
+
) -> DeltaRegionOutput:
|
| 389 |
+
"""Edit FLAME identities from text (deterministic, inference mode).
|
| 390 |
+
|
| 391 |
+
Args:
|
| 392 |
+
prompts: One prompt or a list of ``B`` prompts, e.g. ``"make the nose long"``.
|
| 393 |
+
source_shape: ``(300,)``, ``(1, 300)`` or ``(B, 300)`` FLAME 2020 shape
|
| 394 |
+
coefficients. Defaults to the neutral (all-zero) identity.
|
| 395 |
+
prior_scale: Edit-strength knob (defaults to ``config.inference_prior_scale``).
|
| 396 |
+
tokenizer: Optional tokenizer; defaults to the one bundled with the model.
|
| 397 |
+
"""
|
| 398 |
+
if isinstance(prompts, str):
|
| 399 |
+
prompts = [prompts]
|
| 400 |
+
batch_size = len(prompts)
|
| 401 |
+
device, dtype = self.text_proj.weight.device, self.text_proj.weight.dtype
|
| 402 |
+
|
| 403 |
+
if source_shape is None:
|
| 404 |
+
source_shape = torch.zeros(batch_size, self.config.shape_dim)
|
| 405 |
+
source_shape = torch.as_tensor(source_shape).to(device=device, dtype=dtype)
|
| 406 |
+
if source_shape.dim() == 1:
|
| 407 |
+
source_shape = source_shape.unsqueeze(0)
|
| 408 |
+
if source_shape.shape[-1] != self.config.shape_dim:
|
| 409 |
+
raise ValueError(
|
| 410 |
+
f"source_shape must have {self.config.shape_dim} FLAME shape coefficients, "
|
| 411 |
+
f"got {source_shape.shape[-1]} (zero-pad shorter shape vectors)."
|
| 412 |
+
)
|
| 413 |
+
if source_shape.shape[0] == 1 and batch_size > 1:
|
| 414 |
+
source_shape = source_shape.expand(batch_size, -1)
|
| 415 |
+
if source_shape.shape[0] != batch_size:
|
| 416 |
+
raise ValueError(f"Got {batch_size} prompts but {source_shape.shape[0]} source shapes.")
|
| 417 |
+
|
| 418 |
+
tokens = self.tokenize(prompts, tokenizer=tokenizer)
|
| 419 |
+
was_training = self.training
|
| 420 |
+
self.eval()
|
| 421 |
+
try:
|
| 422 |
+
return self(
|
| 423 |
+
input_ids=tokens["input_ids"].to(device),
|
| 424 |
+
attention_mask=tokens["attention_mask"].to(device),
|
| 425 |
+
source_shape=source_shape,
|
| 426 |
+
prior_scale=prior_scale,
|
| 427 |
+
)
|
| 428 |
+
finally:
|
| 429 |
+
self.train(was_training)
|
| 430 |
+
|
| 431 |
+
def region_probabilities(self, gate: torch.Tensor) -> list:
|
| 432 |
+
"""Map a ``(B, K)`` gate tensor to a list of ``{region: probability}`` dicts."""
|
| 433 |
+
return [dict(zip(self.attribute_names, row.tolist())) for row in gate.detach().cpu()]
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
__all__ = ["DeltaRegionConfig", "DeltaRegionModel", "DeltaRegionOutput", "DeltaRegionPreTrainedModel"]
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"additional_special_tokens": [
|
| 3 |
+
"<extra_id_0>",
|
| 4 |
+
"<extra_id_1>",
|
| 5 |
+
"<extra_id_2>",
|
| 6 |
+
"<extra_id_3>",
|
| 7 |
+
"<extra_id_4>",
|
| 8 |
+
"<extra_id_5>",
|
| 9 |
+
"<extra_id_6>",
|
| 10 |
+
"<extra_id_7>",
|
| 11 |
+
"<extra_id_8>",
|
| 12 |
+
"<extra_id_9>",
|
| 13 |
+
"<extra_id_10>",
|
| 14 |
+
"<extra_id_11>",
|
| 15 |
+
"<extra_id_12>",
|
| 16 |
+
"<extra_id_13>",
|
| 17 |
+
"<extra_id_14>",
|
| 18 |
+
"<extra_id_15>",
|
| 19 |
+
"<extra_id_16>",
|
| 20 |
+
"<extra_id_17>",
|
| 21 |
+
"<extra_id_18>",
|
| 22 |
+
"<extra_id_19>",
|
| 23 |
+
"<extra_id_20>",
|
| 24 |
+
"<extra_id_21>",
|
| 25 |
+
"<extra_id_22>",
|
| 26 |
+
"<extra_id_23>",
|
| 27 |
+
"<extra_id_24>",
|
| 28 |
+
"<extra_id_25>",
|
| 29 |
+
"<extra_id_26>",
|
| 30 |
+
"<extra_id_27>",
|
| 31 |
+
"<extra_id_28>",
|
| 32 |
+
"<extra_id_29>",
|
| 33 |
+
"<extra_id_30>",
|
| 34 |
+
"<extra_id_31>",
|
| 35 |
+
"<extra_id_32>",
|
| 36 |
+
"<extra_id_33>",
|
| 37 |
+
"<extra_id_34>",
|
| 38 |
+
"<extra_id_35>",
|
| 39 |
+
"<extra_id_36>",
|
| 40 |
+
"<extra_id_37>",
|
| 41 |
+
"<extra_id_38>",
|
| 42 |
+
"<extra_id_39>",
|
| 43 |
+
"<extra_id_40>",
|
| 44 |
+
"<extra_id_41>",
|
| 45 |
+
"<extra_id_42>",
|
| 46 |
+
"<extra_id_43>",
|
| 47 |
+
"<extra_id_44>",
|
| 48 |
+
"<extra_id_45>",
|
| 49 |
+
"<extra_id_46>",
|
| 50 |
+
"<extra_id_47>",
|
| 51 |
+
"<extra_id_48>",
|
| 52 |
+
"<extra_id_49>",
|
| 53 |
+
"<extra_id_50>",
|
| 54 |
+
"<extra_id_51>",
|
| 55 |
+
"<extra_id_52>",
|
| 56 |
+
"<extra_id_53>",
|
| 57 |
+
"<extra_id_54>",
|
| 58 |
+
"<extra_id_55>",
|
| 59 |
+
"<extra_id_56>",
|
| 60 |
+
"<extra_id_57>",
|
| 61 |
+
"<extra_id_58>",
|
| 62 |
+
"<extra_id_59>",
|
| 63 |
+
"<extra_id_60>",
|
| 64 |
+
"<extra_id_61>",
|
| 65 |
+
"<extra_id_62>",
|
| 66 |
+
"<extra_id_63>",
|
| 67 |
+
"<extra_id_64>",
|
| 68 |
+
"<extra_id_65>",
|
| 69 |
+
"<extra_id_66>",
|
| 70 |
+
"<extra_id_67>",
|
| 71 |
+
"<extra_id_68>",
|
| 72 |
+
"<extra_id_69>",
|
| 73 |
+
"<extra_id_70>",
|
| 74 |
+
"<extra_id_71>",
|
| 75 |
+
"<extra_id_72>",
|
| 76 |
+
"<extra_id_73>",
|
| 77 |
+
"<extra_id_74>",
|
| 78 |
+
"<extra_id_75>",
|
| 79 |
+
"<extra_id_76>",
|
| 80 |
+
"<extra_id_77>",
|
| 81 |
+
"<extra_id_78>",
|
| 82 |
+
"<extra_id_79>",
|
| 83 |
+
"<extra_id_80>",
|
| 84 |
+
"<extra_id_81>",
|
| 85 |
+
"<extra_id_82>",
|
| 86 |
+
"<extra_id_83>",
|
| 87 |
+
"<extra_id_84>",
|
| 88 |
+
"<extra_id_85>",
|
| 89 |
+
"<extra_id_86>",
|
| 90 |
+
"<extra_id_87>",
|
| 91 |
+
"<extra_id_88>",
|
| 92 |
+
"<extra_id_89>",
|
| 93 |
+
"<extra_id_90>",
|
| 94 |
+
"<extra_id_91>",
|
| 95 |
+
"<extra_id_92>",
|
| 96 |
+
"<extra_id_93>",
|
| 97 |
+
"<extra_id_94>",
|
| 98 |
+
"<extra_id_95>",
|
| 99 |
+
"<extra_id_96>",
|
| 100 |
+
"<extra_id_97>",
|
| 101 |
+
"<extra_id_98>",
|
| 102 |
+
"<extra_id_99>"
|
| 103 |
+
],
|
| 104 |
+
"eos_token": "</s>",
|
| 105 |
+
"pad_token": "<pad>",
|
| 106 |
+
"unk_token": "<unk>"
|
| 107 |
+
}
|
spiece.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d60acb128cf7b7f2536e8f38a5b18a05535c9e14c7a355904270e15b0945ea86
|
| 3 |
+
size 791656
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@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17 |
+
"<extra_id_14>",
|
| 18 |
+
"<extra_id_15>",
|
| 19 |
+
"<extra_id_16>",
|
| 20 |
+
"<extra_id_17>",
|
| 21 |
+
"<extra_id_18>",
|
| 22 |
+
"<extra_id_19>",
|
| 23 |
+
"<extra_id_20>",
|
| 24 |
+
"<extra_id_21>",
|
| 25 |
+
"<extra_id_22>",
|
| 26 |
+
"<extra_id_23>",
|
| 27 |
+
"<extra_id_24>",
|
| 28 |
+
"<extra_id_25>",
|
| 29 |
+
"<extra_id_26>",
|
| 30 |
+
"<extra_id_27>",
|
| 31 |
+
"<extra_id_28>",
|
| 32 |
+
"<extra_id_29>",
|
| 33 |
+
"<extra_id_30>",
|
| 34 |
+
"<extra_id_31>",
|
| 35 |
+
"<extra_id_32>",
|
| 36 |
+
"<extra_id_33>",
|
| 37 |
+
"<extra_id_34>",
|
| 38 |
+
"<extra_id_35>",
|
| 39 |
+
"<extra_id_36>",
|
| 40 |
+
"<extra_id_37>",
|
| 41 |
+
"<extra_id_38>",
|
| 42 |
+
"<extra_id_39>",
|
| 43 |
+
"<extra_id_40>",
|
| 44 |
+
"<extra_id_41>",
|
| 45 |
+
"<extra_id_42>",
|
| 46 |
+
"<extra_id_43>",
|
| 47 |
+
"<extra_id_44>",
|
| 48 |
+
"<extra_id_45>",
|
| 49 |
+
"<extra_id_46>",
|
| 50 |
+
"<extra_id_47>",
|
| 51 |
+
"<extra_id_48>",
|
| 52 |
+
"<extra_id_49>",
|
| 53 |
+
"<extra_id_50>",
|
| 54 |
+
"<extra_id_51>",
|
| 55 |
+
"<extra_id_52>",
|
| 56 |
+
"<extra_id_53>",
|
| 57 |
+
"<extra_id_54>",
|
| 58 |
+
"<extra_id_55>",
|
| 59 |
+
"<extra_id_56>",
|
| 60 |
+
"<extra_id_57>",
|
| 61 |
+
"<extra_id_58>",
|
| 62 |
+
"<extra_id_59>",
|
| 63 |
+
"<extra_id_60>",
|
| 64 |
+
"<extra_id_61>",
|
| 65 |
+
"<extra_id_62>",
|
| 66 |
+
"<extra_id_63>",
|
| 67 |
+
"<extra_id_64>",
|
| 68 |
+
"<extra_id_65>",
|
| 69 |
+
"<extra_id_66>",
|
| 70 |
+
"<extra_id_67>",
|
| 71 |
+
"<extra_id_68>",
|
| 72 |
+
"<extra_id_69>",
|
| 73 |
+
"<extra_id_70>",
|
| 74 |
+
"<extra_id_71>",
|
| 75 |
+
"<extra_id_72>",
|
| 76 |
+
"<extra_id_73>",
|
| 77 |
+
"<extra_id_74>",
|
| 78 |
+
"<extra_id_75>",
|
| 79 |
+
"<extra_id_76>",
|
| 80 |
+
"<extra_id_77>",
|
| 81 |
+
"<extra_id_78>",
|
| 82 |
+
"<extra_id_79>",
|
| 83 |
+
"<extra_id_80>",
|
| 84 |
+
"<extra_id_81>",
|
| 85 |
+
"<extra_id_82>",
|
| 86 |
+
"<extra_id_83>",
|
| 87 |
+
"<extra_id_84>",
|
| 88 |
+
"<extra_id_85>",
|
| 89 |
+
"<extra_id_86>",
|
| 90 |
+
"<extra_id_87>",
|
| 91 |
+
"<extra_id_88>",
|
| 92 |
+
"<extra_id_89>",
|
| 93 |
+
"<extra_id_90>",
|
| 94 |
+
"<extra_id_91>",
|
| 95 |
+
"<extra_id_92>",
|
| 96 |
+
"<extra_id_93>",
|
| 97 |
+
"<extra_id_94>",
|
| 98 |
+
"<extra_id_95>",
|
| 99 |
+
"<extra_id_96>",
|
| 100 |
+
"<extra_id_97>",
|
| 101 |
+
"<extra_id_98>",
|
| 102 |
+
"<extra_id_99>"
|
| 103 |
+
],
|
| 104 |
+
"eos_token": "</s>",
|
| 105 |
+
"extra_ids": 100,
|
| 106 |
+
"model_max_length": 512,
|
| 107 |
+
"name_or_path": "google/t5-v1_1-large",
|
| 108 |
+
"pad_token": "<pad>",
|
| 109 |
+
"sp_model_kwargs": {},
|
| 110 |
+
"tokenizer_class": "T5Tokenizer",
|
| 111 |
+
"unk_token": "<unk>"
|
| 112 |
+
}
|