Skip to main content
Back

Shanghai Jiao Tong's A²-Edit Beats Specialized AI Editors With Rough Sketches

A2-Edit combines a Mixture of Transformers with a coarse-to-fine mask training curriculum to swap any object in an image from a rough scribble.

Pro

  • A²-Edit unifies reference-guided inpainting across arbitrary object categories using only a coarse user mask.
  • Built on FLUX.1 Fill, it adds Mixture of Transformers routing to both attention and FFN layers via LoRA experts.
  • Mask Annealing Training Strategy progressively degrades masks from fine to bounding box to reduce reliance on precise input.
  • UniEdit-500K dataset provides 500,104 pairs across 8 categories and 209 subcategories for unified training.
  • Beats MimicBrush, ACE++, InsertAnything, and FLUX.1-Kontext on VITON-HD, AnyInsertion, and UniEdit benchmarks.
  • Code and dataset promised at publication; struggles when masks are excessively large or cover rare categories.

Reference-guided image inpainting has become a workhorse for virtual try-on, product placement, and identity-preserving edits, but almost every model in this space cheats in one of two ways: it specializes in a single category (garments, faces, pets) or it demands a pixel-accurate segmentation mask that no real user would ever draw. A team from Shanghai Jiao Tong University is pushing back on both assumptions with A²-Edit, a unified framework that handles arbitrary object categories from a coarse mask and still beats specialized baselines on their home turf.

The dual failure mode of current editors

The paper frames the problem cleanly. Garment editing emphasizes texture consistency, portrait editing focuses on identity preservation and morphological variations, and rigid objects require accurate geometric and material representation. These objectives are fundamentally different, yet most models route everything through a shared parameter pathway, which causes cross-category degradation. On top of that, existing training sets skew heavily toward a handful of domains, and when mask quality deteriorates, model performance degrades significantly, making the models fragile the moment a user draws a rough box instead of a perfect silhouette.

Splitting the transformer, not just the FFN

The core architectural contribution is a Mixture of Transformers (MoT) built on top of FLUX.1 Fill. Standard mixture-of-experts approaches only swap experts inside the feed-forward layers and leave attention shared across all inputs. The authors argue that different object categories need different relational modeling, not just different content transformations, so they extend expert routing into attention as well.

A2-Edit pipeline with encoders, DiT backbone, MoT expert routing, and three-stage training

Each expert is implemented as a lightweight LoRA adapter of rank 32, applied to the Q, K, V projections and both FFN linears. The routing itself uses what they call Anchor-Guided Routing: a backbone expert is always active to provide shared knowledge, and assistant experts join in only if their routing weight beats the backbone's. Routing is computed once per layer and reused across attention and FFN, so the extra machinery stays cheap. In numbers, the model reaches a peak memory usage of 42 GB (42,074 MiB), which is slightly higher than the 39,884 MiB required by the baseline model, and inference actually gets slightly faster than the FLUX.1 Fill baseline at 1024x1024.

Teaching the model to tolerate bad masks

The second half of the recipe is the Mask Annealing Training Strategy (MATS), a three-stage curriculum that progressively degrades mask quality:

  1. Fine masks aligned to the object (3000 steps) to learn basic placement.
  2. Rough masks generated by morphological dilation plus Perlin noise on the contour points, simulating human sketch errors (1500 steps).
  3. Bounding box masks with no shape prior, forcing the model to infer pose and scale from context (1500 steps).

The ablation is telling: training only with fine masks tanks rough-mask performance, while adding rough and bounding box stages recovers it and improves fine-mask results too.

UniEdit-500K: the missing training set

Because no existing dataset covers this breadth, the authors built one. The dataset contains over 500,000 reference-target image pairs, covering 8 major categories and 209 fine-grained subcategories, spanning diverse object types including texture-dominant non-rigid objects and structure-dominant rigid objects. The categories are garments, portraits, animals, plants, accessories, furniture, vehicles, and architecture. Portraits and animals come from VidGen-1M video frames filtered with Grounding DINO and SAM, garments extend VITON-HD and DressCode, and the rigid categories use multi-view images plus NanoBanana-generated fills to balance the distribution.

UniEdit-500K category distribution across eight object categories with sample images and word cloud

The scoreboard

On VITON-HD and AnyInsertion, A²-Edit takes the top spot on DINO-I, CLIP-I, and LPIPS under both fine and rough masks. The interesting result is what happens when masks get worse:

MethodFine DINO-IRough DINO-IDrop
FLUX.1-Kontext59.4954.15-5.34
Insert Anything60.9060.50-0.40
A²-Edit61.6761.73+0.06

A²-Edit is essentially flat between fine and rough masks on AnyInsertion, while FLUX.1-Kontext loses more than five points. On the multi-category UniEdit test set the margin widens further, with a VLM-judged score of 79.3 under rough masks versus 75.0 for the next-best model.

What it is good at, and what it is not

The obvious wins are virtual try-on, portrait and pet face swaps, and product placement scenes where the user only has a rough box to work with. The multi-step editing experiments also suggest it holds up across chained edits without drifting.

The authors are upfront about the limits: even though MATS enhances the model's robustness to rough masks, it may struggle to accurately infer the editing intent when the provided mask is excessively large, the MoT routing costs extra memory, and rare or highly specialized object categories are still underrepresented in UniEdit-500K. Code and dataset will be released upon publication, so the reproducibility story depends on that release landing.