Multi-instance image generation (MIG) remains a significant challenge for modern diffusion models due to key limitations in achieving precise control over object layout and preserving the identity of multiple distinct subjects. To address these limitations, we introduce ContextGen, a novel Diffusion Transformer framework for multi-instance generation based on contextual learning guided by both layout and reference images. Our approach integrates two key technical contributions: a Contextual Layout Anchoring (CLA) mechanism that incorporates the composite layout image into the generation context to robustly anchor the objects in their desired positions, and Identity Consistency Attention (ICA), a innovative attention mechanism which leverages contextual reference images to ensure the identity consistency of multiple instances. Recognizing the lack of large-scale, hierarchically-structured datasets for this task, we introduce IMIG-100K, the first dataset with detailed layout and identity annotations. Extensive experiments demonstrate that ContextGen sets a new state-of-the-art, outperforming existing methods in control precision, identity fidelity, and overall visual quality.
In our framework, a composite layout image is used for precise spatial control, this layout image can be either user-provided or automatically synthesized in setup stage. Then we integrate reference images to overcome the limitations of layout-only generation, such as instance information loss due to overlaps and dimensional compression. Our method introduces two key innovations: (1) Contextual Layout Anchoring (CLA), which leverages contextual learning to anchor each instance at its desired position by incorporating the layout image into the generation context, thereby achieving robust layout control; and (2) Identity Consistency Attention (ICA), a novel attention mechanism which propagates fine-grained information from contextual reference images to their respective desired locations, thereby preserving the identity of multiple instances. Complementing these mechanisms is an enhanced position indexing strategy that systematically organizes and differentiates multi-image relationships.
@article{xu2025contextgencontextuallayoutanchoring,
title={ContextGen: Contextual Layout Anchoring for Identity-Consistent Multi-Instance Generation},
author={Ruihang Xu and Dewei Zhou and Fan Ma and Yi Yang},
year={2025},
eprint={2510.11000},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2510.11000},
}