Buckets:
| # DiT | |
| [基于 Transformer 的可扩展扩散模型](https://huggingface.co/papers/2212.09748)(DiT)由 William Peebles 和 Saining Xie 提出。 | |
| 该论文的摘要如下: | |
| *我们探索了一类基于 Transformer 架构的新型扩散模型。我们训练了图像的潜在扩散模型,用在潜在块(latent patches)上操作的 Transformer 替换了常用的 U-Net 骨干网络。我们通过前向传播复杂度(以 Gflops 衡量)来分析我们的 Diffusion Transformers(DiTs)的可扩展性。我们发现,具有更高 Gflops 的 DiTs——无论是通过增加 Transformer 的深度/宽度,还是通过增加输入 token 的数量——始终具有更低的 FID。除了具备良好的可扩展性外,我们最大的 DiT-XL/2 模型在类别条件 ImageNet 512x512 和 256x256 基准测试上超越了所有先前的扩散模型,并在后者上达到了 2.27 的 SOTA FID。* | |
| 原始代码库可在 [facebookresearch/dit](https://github.com/facebookresearch/dit) 中找到。 | |
| > [!TIP] | |
| > 请务必参阅 [调度器指南](../../using-diffusers/schedulers),了解如何探索调度器速度与质量之间的权衡,并查看 [跨流水线复用组件](../../using-diffusers/loading#reusing-models-in-multiple-pipelines) 部分,了解如何高效地将相同组件加载到多个流水线中。 | |
| ## DiTPipeline[[diffusers.DiTPipeline]] | |
| #### diffusers.DiTPipeline[[diffusers.DiTPipeline]] | |
| ```python | |
| diffusers.DiTPipeline(transformer: DiTTransformer2DModel, vae: AutoencoderKL, scheduler: KarrasDiffusionSchedulers, id2label: dict[int, str] | None = None) | |
| ``` | |
| [源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dit/pipeline_dit.py#L38) | |
| **参数:** | |
| transformer ([DiTTransformer2DModel](/docs/diffusers/v0.43.0/zh/api/models/dit_transformer2d#diffusers.DiTTransformer2DModel)):一个带条件输入的 `DiTTransformer2DModel` 类,用于对编码后的图像潜变量进行去噪。在配置中最初发布为 [`Transformer2DModel`](https://huggingface.co/facebook/DiT-XL-2-256/blob/main/transformer/config.json#L2),但该名称不一致可以忽略。 | |
| vae ([AutoencoderKL](/docs/diffusers/v0.43.0/zh/api/models/autoencoderkl#diffusers.AutoencoderKL)):变分自编码器(VAE)模型,用于将图像编码为潜在表示,并从潜在表示解码回图像。 | |
| scheduler ([DDIMScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/ddim#diffusers.DDIMScheduler)):一种调度器,需与 `transformer` 配合使用,以对编码后的图像潜变量进行去噪。 | |
| 基于 Transformer 主干而非 UNet 的图像生成 Pipeline。 | |
| 该模型继承自 [DiffusionPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/overview#diffusers.DiffusionPipeline)。有关为所有流水线实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。 | |
| #### __调用__[[diffusers.DiTPipeline.__call__]] | |
| ```python | |
| __call__(class_labels: list[int], guidance_scale: float = 4.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, num_inference_steps: int = 50, output_type: str | None = 'pil', return_dict: bool = True) | |
| ``` | |
| [源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dit/pipeline_dit.py#L101) | |
| **参数:** | |
| class_labels (list[int]) : 要生成的图像的 ImageNet 类别标签列表。 | |
| guidance_scale (`float`, *可选*,默认值为 4.0):较高的 guidance scale 值会促使模型生成与文本 `prompt` 紧密关联的图像,但代价是图像质量降低。当 `guidance_scale > 1` 时,guidance scale 生效。 | |
| generator (`torch.Generator`, *可选*) : 一个 [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html),用于使生成过程具有确定性。 | |
| num_inference_steps (`int`, *可选*,默认为 250):去噪步数。更多的去噪步数通常能带来更高质量的图像,但代价是推理速度变慢。 | |
| output_type (`str`,*可选*,默认为 `"pil"`):生成图像的输出格式。可选 `"pil"`(`PIL.Image`)、`"np"`(`np.array`)或 `"pt"`(`torch.Tensor`)。 | |
| return_dict (`bool`,*可选*,默认为 `True`):是否返回 [ImagePipelineOutput](/docs/diffusers/v0.43.0/zh/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) 而不是普通元组。 | |
| **返回:** [ImagePipelineOutput](/docs/diffusers/v0.43.0/zh/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) 或 `tuple` | |
| 如果 `return_dict` 为 `True`,则返回 [ImagePipelineOutput](/docs/diffusers/v0.43.0/zh/api/pipelines/consistency_models#diffusers.ImagePipelineOutput),否则返回一个 `tuple`,其中第一个元素是包含生成图像的列表 | |
| 用于生成的 pipeline 的调用函数。 | |
| 示例: | |
| ```py | |
| >>> from diffusers import DiTPipeline, DPMSolverMultistepScheduler | |
| >>> import torch | |
| >>> pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-256", torch_dtype=torch.float16) | |
| >>> pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) | |
| >>> pipe = pipe.to("cuda") | |
| >>> # pick words from Imagenet class labels | |
| >>> pipe.labels # to print all available words | |
| >>> # pick words that exist in ImageNet | |
| >>> words = ["white shark", "umbrella"] | |
| >>> class_ids = pipe.get_label_ids(words) | |
| >>> generator = torch.manual_seed(33) | |
| >>> output = pipe(class_labels=class_ids, num_inference_steps=25, generator=generator) | |
| >>> image = output.images[0] # label 'white shark' | |
| ``` | |
| #### get_label_ids[[diffusers.DiTPipeline.get_label_ids]] | |
| ```python | |
| get_label_ids(label: str | list[str]) | |
| ``` | |
| [源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/dit/pipeline_dit.py#L76) | |
| **参数:** | |
| label (`str` 或 `dict` of `str`) : 要映射到类别 ID 的标签字符串。 | |
| **返回:** `list` 类型的 `int` | |
| 要由 pipeline 处理的类别 ID。 | |
| 将 ImageNet 的标签字符串映射到对应的类别 ID。 | |
| ## ImagePipelineOutput[[diffusers.ImagePipelineOutput]] | |
| #### diffusers.ImagePipelineOutput[[diffusers.ImagePipelineOutput]] | |
| ```python | |
| diffusers.ImagePipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray) | |
| ``` | |
| [源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/pipeline_utils.py#L135) | |
| **参数:** | |
| images (`List[PIL.Image.Image]` 或 `np.ndarray`):长度为 `batch_size` 的去噪 PIL 图像列表,或形状为 `(batch_size, height, width, num_channels)` 的 NumPy 数组。 | |
| 图像流水线输出类。 | |
Xet Storage Details
- Size:
- 6.5 kB
- Xet hash:
- d74f512aa13d0c7729b028d5556f3919bbfbcfd2482aeae8aeec41dd7cb3134c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.