# 文本到图像生成

文本到图像生成是一种机器学习方法，它根据被称为提示词的自然语言文本描述生成图像。现代系统主要分为两大流派：扩散模型，在自编码器的潜空间或像素空间中迭代地对图像去噪；以及自回归变换器，像处理序列一样逐词元生成图像。DALL-E 是此类中第一个大规模自回归系统，它将文本词元和图像词元视为单一流，在零样本条件下与早期领域专用模型相比具有竞争力<sup>[1](https://proceedings.mlr.press/v139/ramesh21a.html)</sup>；而潜扩散则使以卷积方式实现高分辨率合成成为可能。<sup>[2](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach%5FHigh-Resolution%5FImage%5FSynthesis%5FWith%5FLatent%5FDiffusion%5FModels%5FCVPR%5F2022%5Fpaper.pdf)</sup>

| 关键事实 | 数值 | 来源 |
|---|---|---|
| 输入与输出 | 输入一段文本提示词，输出一张图像 | <sup>[1](https://proceedings.mlr.press/v139/ramesh21a.html)</sup> |
| DALL-E（2021） | 120亿参数的自回归变换器，在2.5亿个图文对上训练 | <sup>[1](https://proceedings.mlr.press/v139/ramesh21a.html)</sup> |
| 潜扩散 | 在预训练自编码器的潜空间中通过交叉注意力进行扩散；14.5亿参数模型，在LAION-400M上训练 | <sup>[2](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach%5FHigh-Resolution%5FImage%5FSynthesis%5FWith%5FLatent%5FDiffusion%5FModels%5FCVPR%5F2022%5Fpaper.pdf)</sup> |
| Imagen（2022） | 未在COCO上训练的情况下，在MS-COCO上零样本FID为7.27 | <sup>[3](https://papers.neurips.cc/paper_files/paper/2022/file/ec795aeadae0b7d230fa35cbaf04c041-Paper-Conference.pdf)</sup> |
| Parti（2022） | 200亿参数的编码器-解码器；零样本FID 7.23，微调后FID 3.22（MS-COCO） | <sup>[4](https://arxiv.org/pdf/2206.10789)</sup> |
| Stable Diffusion v1 默认设置 | 引导尺度7.5，PLMS采样器，512×512下50步；可在显存至少10GB的GPU上运行 | <sup>[5](https://github.com/CompVis/stable-diffusion?tab=readme-ov-file)</sup> |
| Stable Diffusion 3（2024） | 80亿参数；在RTX 4090上以50个采样步生成1024×1024图像需34秒 | <sup>[6](https://stability.ai/news-updates/stable-diffusion-3-research-paper)</sup> |

## 工作原理

扩散模型通过逐步对服从正态分布的变量去噪来学习数据分布，这一过程是长度为T的固定[马尔可夫链](https://www.edgepedia.org/zh/markov-chain)的逆过程。<sup>[2](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach%5FHigh-Resolution%5FImage%5FSynthesis%5FWith%5FLatent%5FDiffusion%5FModels%5FCVPR%5F2022%5Fpaper.pdf)</sup> 网络是一个时间条件UNet，经过训练来预测每一步所添加的噪声；潜扩散损失为 \( L_{\mathrm{LDM}} := \mathbb{E}\,\lVert \epsilon - \epsilon_{\theta}(z_{t}, t, \tau_{\theta}(y)) \rVert_{2}^{2} \)，其中文本编码器 \( \tau_{\theta} \) 将提示词投影为中间表示，通过交叉注意力层注入，编码器与去噪器联合优化。<sup>[2](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach%5FHigh-Resolution%5FImage%5FSynthesis%5FWith%5FLatent%5FDiffusion%5FModels%5FCVPR%5F2022%5Fpaper.pdf)</sup> 在自编码器的潜空间中工作，比像素扩散至少提速2.7倍，同时FID至少改善1.6倍。<sup>[2](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach%5FHigh-Resolution%5FImage%5FSynthesis%5FWith%5FLatent%5FDiffusion%5FModels%5FCVPR%5F2022%5Fpaper.pdf)</sup>

文本编码的选择至关重要。Imagen 发现，扩大冻结的T5-XXL编码器（46亿参数）比扩大扩散模型本身更能提升对齐度和保真度。<sup>[3](https://papers.neurips.cc/paper_files/paper/2022/file/ec795aeadae0b7d230fa35cbaf04c041-Paper-Conference.pdf)</sup> SDXL 将 OpenCLIP ViT-bigG 和 CLIP ViT-L 的倒数第二层输出沿通道轴拼接。<sup>[7](https://doi.org/10.48550/arxiv.2307.01952)</sup> 条件强度由无分类器引导控制：训练时随机丢弃条件（例如以10%的概率），使一个模型同时学习条件和无条件目标；采样时施加引导权重 \( w \)，其中 \( w = 1 \) 禁用引导，\( w > 1 \) 增强对提示词的遵循。<sup>[3](https://papers.neurips.cc/paper_files/paper/2022/file/ec795aeadae0b7d230fa35cbaf04c041-Paper-Conference.pdf)</sup>

自回归模型则对图像进行离散化。DALL-E 将最多256个[BPE](https://www.edgepedia.org/zh/byte-pair-encoding)文本词元与32×32 = 1024个图像词元拼接，并对该流进行自回归建模。<sup>[1](https://proceedings.mlr.press/v139/ramesh21a.html)</sup> Parti 将任务视为序列到序列建模，用 ViT-VQGAN 将图像编码为离散词元序列。<sup>[8](https://sites.research.google/parti/)</sup> [DALL-E 2](https://www.edgepedia.org/zh/dall-e-2)（unCLIP）混合了两大流派：先验模型从图像描述生成 CLIP 图像嵌入，扩散解码器——35亿参数的 GLIDE 模型——以该嵌入为条件生成图像。<sup>[9](https://cdn.openai.com/papers/dall-e-2.pdf)</sup>

## 操作方式

实践者选择一个模型，编写提示词，固定种子，然后运行采样器。[Stable Diffusion](https://www.edgepedia.org/zh/stable-diffusion) v1 将一个下采样因子为8的自编码器与8.6亿参数的UNet和一个冻结的CLIP ViT-L/14文本编码器配对。<sup>[5](https://github.com/CompVis/stable-diffusion?tab=readme-ov-file)</sup> 其参考设置为引导尺度7.5、PLMS采样器、512×512下50步，引导按 \( \epsilon = \epsilon(x, \varnothing) + \mathrm{scale} \cdot (\epsilon(x, \mathrm{cond}) - \epsilon(x, \varnothing)) \) 施加。<sup>[5](https://github.com/CompVis/stable-diffusion?tab=readme-ov-file)</sup> 在 Diffusers 库中，潜扩散流水线默认50个推理步、guidance_scale 为1.0；更多步数提升质量但增加延迟，更高的引导使图像更贴近提示词，但以图像质量为代价。<sup>[10](https://huggingface.co/docs/diffusers/main/en/api/pipelines/latent_diffusion)</sup>

种子不是细节问题。在 Stable Diffusion 2.0 上使用1,024个种子和超过22,000条提示词，最佳种子的FID为21.60，最差为31.97，且分类器能以超过99.9%的验证准确率从图像中识别出种子，表明初始噪声潜变量在很大程度上决定了输出。<sup>[11](https://arxiv.org/pdf/2405.14828)</sup> 在更高分辨率下，Imagen 的动态阈值化将每一步的预测裁剪到百分位范围，从而在大的引导权重下避免饱和伪影<sup>[3](https://papers.neurips.cc/paper_files/paper/2022/file/ec795aeadae0b7d230fa35cbaf04c041-Paper-Conference.pdf)</sup>；SDXL 在接近 \( 1024^{2} \) 像素的宽高比桶上以1000步调度训练，事后应用单独的细化模型。<sup>[7](https://doi.org/10.48550/arxiv.2307.01952)</sup>

## 起源

文本到图像合成领域由斯科特·里德（Scott Reed）及其同事2016年的GAN方法开创，发表在arXiv上，该方法在受限数据集上根据图像描述生成64×64的鸟类和花卉图像。<sup>[12](https://arxiv.org/pdf/2101.09983v2.pdf)</sup><sup> • </sup><sup>[13](https://doi.org/10.48550/arxiv.1605.05396)</sup> 更早的2015年，卡罗尔·格雷戈尔（Karol Gregor）及其同事以图像描述作为DRAW循环生成模型的条件，一篇综述将其标记为现代工作的开端。<sup>[14](https://arxiv.org/html/2505.02527)</sup>

规模扩展发生在2021至2022年。阿迪蒂亚·拉梅什（Aditya Ramesh）及其同事的DALL-E在2.5亿个图文对上训练了一个120亿参数的变换器<sup>[1](https://proceedings.mlr.press/v139/ramesh21a.html)</sup>；同期丁明（Ming Ding）及其同事的 [CogView](https://www.edgepedia.org/zh/cogview) 在3000万个图文对上训练了一个40亿参数的变换器。<sup>[14](https://arxiv.org/html/2505.02527)</sup> 亚历克斯·尼科尔（Alex Nichol）及其同事的 GLIDE 训练了一个35亿参数的文本条件扩散模型，即使DALL-E使用了昂贵的CLIP重排序，人类评估者仍更偏好GLIDE的样本<sup>[15](https://doi.org/10.48550/arxiv.2112.10741)</sup>，综述认为这是扩散模型在该任务上的首次应用。<sup>[16](https://arxiv.org/html/2303.07909v3)</sup> DALL-E 2 引入了 [unCLIP](https://www.edgepedia.org/zh/unclip) 先验-解码器设计<sup>[9](https://cdn.openai.com/papers/dall-e-2.pdf)</sup>，Imagen 引入了冻结语言编码器的级联流水线<sup>[3](https://papers.neurips.cc/paper_files/paper/2022/file/ec795aeadae0b7d230fa35cbaf04c041-Paper-Conference.pdf)</sup>，Parti 引入了200亿参数的大规模自回归模型<sup>[4](https://arxiv.org/pdf/2206.10789)</sup>，[罗宾·罗姆巴赫](https://www.edgepedia.org/zh/robin-rombach)（Robin Rombach）及其同事提出了 Stable Diffusion 背后的潜扩散建模方法。<sup>[2](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach%5FHigh-Resolution%5FImage%5FSynthesis%5FWith%5FLatent%5FDiffusion%5FModels%5FCVPR%5F2022%5Fpaper.pdf)</sup>

## 变体

潜扩散在开放实践中占主导地位。SDXL 将UNet扩大到26亿参数，文本编码器为8.17亿参数。<sup>[7](https://doi.org/10.48550/arxiv.2307.01952)</sup> [Stable Diffusion 3](https://www.edgepedia.org/zh/stable-diffusion-3) 用扩散变换器取代UNet，文本词元和图像词元使用两套独立的权重，仅在注意力操作时合并，以整流流训练，整流流将数据与噪声以直线连接<sup>[17](https://arxiv.org/html/2403.03206)</sup>；整流流本身由刘、龚、刘（Liu, Gong, and Liu）于2022年提出<sup>[18](https://doi.org/10.48550/arxiv.2209.03003)</sup>，变换器骨干遵循皮布尔斯和谢（Peebles and Xie）的 Diffusion Transformer。<sup>[19](https://doi.org/10.48550/arxiv.2212.09748)</sup> FLUX.1 延续了这一整流流、变换器设计的谱系。<sup>[20](https://openaccess.thecvf.com/content/CVPR2026/papers/Ma_NAMI_Efficient_Image_Generation_via_Bridged_Progressive_Rectified_Flow_Transformers_CVPR_2026_paper.pdf)</sup>

两大流派表现不同：在一项受控比较中，普通自回归模型 LlamaGen 在所有组合性评估上均不如规模相近的扩散模型 SD-v1.4<sup>[21](https://arxiv.org/html/2410.22775)</sup>，而开源 FLUX 模型展现出与闭源 [DALL-E 3](https://www.edgepedia.org/zh/dall-e-3) 相当的组合能力。<sup>[21](https://arxiv.org/html/2410.22775)</sup> 图像描述的质量成为提升训练效果的手段：DALL-E 3 用描述性图像描述生成器重新为训练集配上描述，并在95%合成描述与5%真实描述的混合上训练<sup>[22](https://cdn.openai.com/papers/dall-e-3.pdf)</sup>，SD3 随后采用 CogVLM 生成的合成描述，以50/50混合。<sup>[17](https://arxiv.org/html/2403.03206)</sup> 少步生成通过渐进蒸馏<sup>[23](https://doi.org/10.48550/arxiv.2202.00512)</sup>和潜一致性模型<sup>[24](https://doi.org/10.48550/arxiv.2310.04378)</sup>走向成熟。

## 应用

GLIDE 模型可微调用于图像修复，实现基于文本的现有图像编辑。<sup>[15](https://doi.org/10.48550/arxiv.2112.10741)</sup> 蒸馏后的少步模型服务于延迟敏感的场景：InstaFlow 在MS COCO 2014-30k上以0.09秒一步生成，FID为13.1<sup>[25](https://doi.org/10.48550/arxiv.2309.06380)</sup>，而SD3在RTX 4090上以1024×1024、50步生成需34秒。<sup>[6](https://stability.ai/news-updates/stable-diffusion-3-research-paper)</sup>

## 局限与替代方案

组合生成是有据可查的弱点。失败模式分为四类：实体缺失、属性绑定错误、空间关系错误和计数错误。<sup>[21](https://arxiv.org/html/2410.22775)</sup> 模型常常忽略否定并允许被禁止的内容，计数错误随目标物体数量增加而增大。<sup>[26](https://arxiv.org/abs/2511.10136)</sup> 文本渲染因扩散生成中的局部性偏差而失败，该偏差限制了长程空间依赖，产生乱序或拼错的字符；一旦输入文本超过约200个字符，性能显著下降，这一阈值与CLIP编码器77词元的限制一致。<sup>[27](https://p.rst.im/q/aclanthology.org/2025.emnlp-main.1070.pdf)</sup> 人口统计偏差也有记录：包含“CEO”和“经理”等词的提示词主要生成白人男性图像，[DALL-E Mini](https://www.edgepedia.org/zh/dall-e-mini) 即使对性别中性的提示词也主要生成男性形象。<sup>[28](https://arxiv.org/html/2407.00138v1)</sup> 评估指标仍不全面：FID、IS、CLIP分数、R-Precision、KID及相关度量各自仅捕捉性能的有限方面<sup>[28](https://arxiv.org/html/2407.00138v1)</sup>，这就是为什么开发了基于目标检测的基准，如 T2I-CompBench<sup>[29](https://doi.org/10.48550/arxiv.2307.06350)</sup>和 GenEval<sup>[30](https://doi.org/10.48550/arxiv.2310.11513)</sup>。补救措施是外部条件或注意力控制：GLIGEN 的框条件、[ControlNet](https://www.edgepedia.org/zh/controlnet) 的结构线索（如边缘和关键点），以及 Attend-and-Excite 的注意力操纵，不过基于训练的修复存在灾难性遗忘的风险，即改善一种组合技能会降低其他技能。<sup>[26](https://arxiv.org/abs/2511.10136)</sup>

## References

1. [Zero-Shot Text-to-Image Generation (DALL-E)](https://proceedings.mlr.press/v139/ramesh21a.html)
2. [High-Resolution Image Synthesis With Latent Diffusion Models (CVPR 2022)](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach%5FHigh-Resolution%5FImage%5FSynthesis%5FWith%5FLatent%5FDiffusion%5FModels%5FCVPR%5F2022%5Fpaper.pdf)
3. [Photorealistic Text-to-Image Diffusion Models with Deep Language Understanding (Imagen)](https://papers.neurips.cc/paper_files/paper/2022/file/ec795aeadae0b7d230fa35cbaf04c041-Paper-Conference.pdf)
4. [Scaling Autoregressive Models for Content-Rich Text-to-Image Generation (Parti)](https://arxiv.org/pdf/2206.10789)
5. [CompVis/stable-diffusion README](https://github.com/CompVis/stable-diffusion?tab=readme-ov-file)
6. [Stable Diffusion 3: Research Paper, Stability AI](https://stability.ai/news-updates/stable-diffusion-3-research-paper)
7. [Podell, Dustin and colleagues (2023). SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2307.01952)
8. [Parti: Pathways Autoregressive Text-to-Image Model (project page)](https://sites.research.google/parti/)
9. [Hierarchical Text-Conditional Image Generation with CLIP Latents (DALL-E 2 / unCLIP)](https://cdn.openai.com/papers/dall-e-2.pdf)
10. [Diffusers documentation: Latent Diffusion pipelines](https://huggingface.co/docs/diffusers/main/en/api/pipelines/latent_diffusion)
11. [Golden Seed: Large-Scale Study of Random Seeds in Text-to-Image Diffusion](https://arxiv.org/pdf/2405.14828)
12. [Adversarial Text-to-Image Synthesis: A Review](https://arxiv.org/pdf/2101.09983v2.pdf)
13. [Reed, Scott and colleagues (2016). Generative Adversarial Text to Image Synthesis. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1605.05396)
14. [Text to Image Generation and Editing: A Survey](https://arxiv.org/html/2505.02527)
15. [Nichol, Alex and colleagues (2021). GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2112.10741)
16. [Text-to-image Diffusion Models in Generative AI: A Survey](https://arxiv.org/html/2303.07909v3)
17. [Scaling Rectified Flow Transformers for High-Resolution Image Synthesis (Stable Diffusion 3)](https://arxiv.org/html/2403.03206)
18. [Liu, Xingchao, Gong, Chengyue, Liu, Qiang (2022). Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2209.03003)
19. [Peebles, William, Xie, Saining (2022). Scalable Diffusion Models with Transformers. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2212.09748)
20. [NAMI: Efficient Image Generation via Bridged Progressive Rectified Flow Transformers](https://openaccess.thecvf.com/content/CVPR2026/papers/Ma_NAMI_Efficient_Image_Generation_via_Bridged_Progressive_Rectified_Flow_Transformers_CVPR_2026_paper.pdf)
21. [Diffusion Beats Autoregressive: An Evaluation of Compositional Generation in Text-to-Image Models](https://arxiv.org/html/2410.22775)
22. [Improving Image Generation with Better Captions (DALL-E 3)](https://cdn.openai.com/papers/dall-e-3.pdf)
23. [Salimans, Tim, Ho, Jonathan (2022). Progressive Distillation for Fast Sampling of Diffusion Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2202.00512)
24. [Luo, Simian and colleagues (2023). Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2310.04378)
25. [Liu, Xingchao and colleagues (2023). InstaFlow: One Step is Enough for High-Quality Diffusion-Based Text-to-Image Generation. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2309.06380)
26. [Right Looks, Wrong Reasons: Compositional Fidelity in Text-to-Image Generation](https://arxiv.org/abs/2511.10136)
27. [STRICT: Stress-Test of Rendering Image Containing Text](https://p.rst.im/q/aclanthology.org/2025.emnlp-main.1070.pdf)
28. [Analyzing Quality, Bias, and Performance in Text-to-Image Generative Models](https://arxiv.org/html/2407.00138v1)
29. [Huang, Kaiyi and colleagues (2023). T2I-CompBench++: An Enhanced and Comprehensive Benchmark for Compositional Text-to-image Generation. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2307.06350)
30. [Ghosh, Dhruba, Hajishirzi, Hanna, Schmidt, Ludwig (2023). GenEval: An Object-Focused Framework for Evaluating Text-to-Image Alignment. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2310.11513)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › Foundation-model methods and training › Generative media methods: diffusion, flow, and autoregressive generation

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/text-to-image-generation

English original: https://www.edgepedia.org/text-to-image-generation
