概述
使用相同的种子、提示、模型和设置,扩散模型通常会重新创建相同的图像。种子可以让您重现结果、进行受控变化并公平地比较设置,尽管精确匹配可能会跨越不同的软件、硬件或模型。
深入探讨
Diffusion models start from pure random noise and refine it step by step into an image. That noise is not truly random. It comes from a pseudorandom number generator, which produces the same sequence of numbers whenever it starts from the same seed. For Stable Diffusion 1.5 at 512 by 512 pixels, the seed fills a latent tensor of 4 channels by 64 by 64 values, and everything the model draws grows out of that pattern. Large shapes, such as where a figure stands or where the horizon falls, are mostly decided in the early steps, so the seed strongly affects composition. Reproducing an image takes more than the seed. You also need the same model weights, prompt, negative prompt, resolution, sampler, step count and guidance scale, plus any extras such as LoRAs or ControlNet inputs. Changing the resolution changes the shape of the noise tensor, so the same seed then gives an unrelated image. Many tools give each image in a batch the next seed number, so the fourth image in a batch is often the starting seed plus three. Exact reproduction can still fail. The CPU and GPU random generators in libraries such as PyTorch produce different sequences from the same seed. Some GPU operations are nondeterministic, half-precision math rounds differently on different hardware, and memory-saving attention code can change tiny values that grow over many steps. Ancestral samplers add fresh noise at every step, which creates more chances for results to drift apart. A different model, or a new version of the same model, turns identical noise into a completely different picture. There are no universally 'good seeds'. A seed that works well for one prompt and model has no special quality anywhere else. Variation features, which blend in a second 'variation seed', let you explore nearby images while keeping the overall layout.
现实世界的实施
一位设计师喜欢用种子 123456 生成的构图,因此她保持该种子固定并将“红色夹克”更改为“蓝色夹克”,以获得密切相关的场景,但更改了一个细节。
比较两个采样器的团队在相同的五个种子上呈现相同的提示,因此任何差异都来自采样器而不是运气。
Midjourney 用户添加 --seed 参数以从同一起点重新运行提示,然后发现不同模型版本的结果仍然不同。
业余爱好者在论坛上分享种子和完整设置,但具有不同 GPU 和软件版本的另一个用户会获得相似但不相同的图像。
种子的未来和人工智能图像生成的可重复性
种子仍将是本地和开放模型的基本控制,用户可以在其中查看每个参数。托管产品各不相同:有些会暴露种子,而另一些则隐藏它们或应用服务器端更改,从而无法精确复制。自回归和混合图像模型在采样时也使用随机性,因此即使机制不同,种子的想法仍然存在。用于记录完整生成配方(包括库版本和硬件)的更好工具将使结果更容易共享和审核。种子无法保证模型版本之间的输出相同,因为权重的任何变化都会改变噪声变成图像的方式。
付诸实践
为什么这很重要
- 速度与规模. 视觉人工智能可以大规模自动化检查、检测和标记任务。
- 构建选择. 创意团队可以通过更少的手动修改更快地构建概念原型。
- 团队与工作流程. 操作可以使用以前难以处理的图像和视频信号。
留意
- 如果出处不明,肖像权和同意可能会成为法律风险。
- 模型性能可能因光照、人口统计和环境的不同而有所不同。
- 除非监控置信阈值,否则误报可能会被忽视。
后续步骤
- 定义精确度、召回率和错误成本的接受标准。
- 使用符合实际生产条件的数据进行测试。
- 为低置信度或高影响力的预测添加人工审核。
- 跟踪模型漂移并在相机或数据集更改后重新验证。
不断探索
常见问题
AI 图像生成中的种子和再现性是什么?
AI 图像生成中的种子是启动产生初始噪声的随机数生成器的数字。使用相同的种子、提示、模型和设置,扩散模型通常会重新创建相同的图像。种子可以让您重现结果、进行受控变化并公平地比较设置,尽管精确匹配可能会跨越不同的软件、硬件或模型。
种子(seed)在扩散图像生成器中直接控制什么?
种子初始化产生初始噪声的随机数生成器,并且模型将该噪声细化到图像中。
为什么保持种子不变但改变分辨率会产生不相关的图像?
不同的分辨率需要不同大小的潜在噪声,因此生成的噪声的布局不同,并且成分完全改变。
由于种子是在早期步骤中决定的,它对图像的哪个方面有强烈影响?
大的形状和布局在去噪的早期就已经确定,并且它们直接从种子产生的起始噪声中生长出来。
为什么相同的种子在 CPU 和 GPU 上会产生不同的噪声?
PyTorch 等库在每个设备上使用单独的随机生成器实现,因此相同的种子会产生不同的数字。
在以种子 500 开始的四张图像批次中,许多工具会将哪个种子分配给第四张图像?
许多工具对批次种子连续编号,因此图像使用 500、501、502 和 503。