chameleon AR head
Two heads live here. head_grid.pt is the default (with code_prior_grid.pt); head_pre.pt (r7, with
code_prior.pt) is the earlier head, kept for existing cartridges and notebooks.
The style describer behind chameleon. Given one or more reference images, it writes their visual style out as a short text description, which then conditions Qwen-Image 2.1 Turbo (as text, or as soft tokens). Qwen-Image itself is not fine-tuned.
Model
- Input: the pooled 1152-d embedding of each reference from the MegaStyle style encoder (
Gaojunyao/MegaStyle, a fine-tuned SigLIP-so400m). - A small MLP maps each embedding to a 256-d code; the codes of several references are averaged into one style code z (the cartridge).
- z becomes 4 memory tokens for a 4-layer causal transformer (width 1024, 16 heads), which writes up to 144 tokens.
It reads and writes tokens through the frozen input-embedding matrix of
Qwen/Qwen3-4B, so its vocabulary is Qwen's. head_grid.pt(default, 59.8M parameters) also reads the style encoder's 4x4 feature grid of the references: their mean grid becomes 16 more memory tokens in front of z's four, which carries local detail (paper, strokes, secondary colours) the pooled vector loses. Cartridges store the grid (about 38 KB instead of 1 KB). Codes with no grid (random styles, or a mix with a grid-less cartridge) use a learned stand-in.head_pre.pt(r7, 58.5M parameters) reads the pooled code only.
Random styles
code_prior_grid.pt (for head_grid.pt) and code_prior.pt (for head_pre.pt) are Gaussians (mean and 256x256
covariance) over the style codes each head assigns to 4,096 training images (1,024 from each of its four MegaStyle
shards). Sampling from it gives a new, plausible style without any
reference image; the same seed always gives the same style with this head and prior.
Training
- Data: 40,000 styles from MegaStyle-1.4M (shards train-00001 to train-00004, 8 images per style) and 1,054
Midjourney sref codes (
peteromallet/high-quality-midjouney-srefs, sampled 3x as often). Targets are the style labels intensorkelechi/chameleon-style-labels. - Objective: teacher-forced cross-entropy on the label text, from the code of 1 to 3 other images of the same style.
- AdamW, learning rate 3e-4, batch 64, 4,500 steps, dropout 0.1, Gaussian noise 0.05 on z. The checkpoint is the
step with the lowest loss on 128 held-out MegaStyle styles from shard train-00099:
head_grid.pt0.931 cross-entropy (step 4,500; 0.945 with its grid removed),head_pre.pt0.942 (step 4,200). - The grid head drops the grid for 20% of training samples, so it also works without one.
- Compute: one A100 40 GB (Colab), about 28 minutes of training per head, after a one-off pass of the style encoder over the images.
Use
from huggingface_hub import hf_hub_download
from chameleon import serve
repo = "tensorkelechi/chameleon-ar-head"
pipe = serve.Pipeline(hf_hub_download(repo, "head_grid.pt"), hf_hub_download(repo, "code_prior_grid.pt"))
cart = pipe.make([style_image], ["my-style"]) # from reference images
text, images = pipe.run(cart, ["a lighthouse on a rocky coast"], [], ref=style_image)
text, images = pipe.run(pipe.random(48213), ["a lighthouse on a rocky coast"], []) # a random style
Limitations
It carries palette, medium, lighting and mood well, and fine texture (brushwork, grain) much less. Random styles lean towards polished digital illustration and photography, the most common looks in the training data.
Licence
Trained on MegaStyle-1.4M, which is released for research use, so this head is for research and non-commercial use only.