百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

Diffusion-Models-pytorch

> 编程语言
开源

Diffusion Models 的 Pytorch 实现 (https://arxiv.org/pdf/2006.11239.pdf)

1.5K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Diffusion Models 的 Pytorch 实现 (https://arxiv.org/pdf/2006.11239.pdf)

Diffusion Models

This is an easy-to-understand implementation of diffusion models within 100 lines of code. Different from other implementations, this code doesn't use the lower-bound formulation for sampling and strictly follows Algorithm 1 from the DDPM paper, which makes it extremely short and easy to follow. There are two implementations: conditional and unconditional. Furthermore, the conditional code also implements Classifier-Free-Guidance (CFG) and Exponential-Moving-Average (EMA). Below you can find two explanation videos for the theory behind diffusion models and the implementation.


Train a Diffusion Model on your own data:

Unconditional Training

  1. (optional) Configure Hyperparameters in ddpm.py
  2. Set path to dataset in ddpm.py
  3. python ddpm.py

Conditional Training

  1. (optional) Configure Hyperparameters in ddpm_conditional.py
  2. Set path to dataset in ddpm_conditional.py
  3. python ddpm_conditional.py

Sampling

The following examples show how to sample images using the models trained in the video on the Landscape Dataset. You can download the checkpoints for the models here.

Unconditional Model

    device = "cuda"
    model = UNet().to(device)
    ckpt = torch.load("unconditional_ckpt.pt")
    model.load_state_dict(ckpt)
    diffusion = Diffusion(img_size=64, device=device)
    x = diffusion.sample(model, n=16)
    plot_images(x)

Conditional Model

This model was trained on CIFAR-10 64x64 with 10 classes airplane:0, auto:1, bird:2, cat:3, deer:4, dog:5, frog:6, horse:7, ship:8, truck:9

    n = 10
    device = "cuda"
    model = UNet_conditional(num_classes=10).to(device)
    ckpt = torch.load("conditional_ema_ckpt.pt")
    model.load_state_dict(ckpt)
    diffusion = Diffusion(img_size=64, device=device)
    y = torch.Tensor([6] * n).long().to(device)
    x = diffusion.sample(model, n, y, cfg_scale=3)
    plot_images(x)

A more advanced version of this code can be found here by @tcapelle. It introduces better logging, faster & more efficient training and other nice features and is also being followed by a nice write-up.

GitHub Issues· 37 开放

在 GitHub 查看全部
  • #42

    Confuse in the 'Sample Fuction'

    更新于 2024年12月8日
  • #47

    I changed the training set of the original code to a class 6 matrix input of 1x512x512

    更新于 2024年12月8日
  • #46

    Weird looking outputs with random artificats/patterns

    更新于 2024年12月7日
  • #45

    Is the pos_encoding function in modules.py correct?

    更新于 2024年10月18日
  • #43

    FileNotFoundError: Couldn't find any class folder in ./datasets/unconditional/landscape

    更新于 2024年8月22日
  • #38

    Is the EMA implementation code in this repository wrong?

    更新于 2024年6月6日
  • #33

    model generating bad random images

    更新于 2024年4月24日
  • #26

    When i change the image_size to 128, the error occurs

    更新于 2024年3月3日
  • #41

    ImportError: DLL load failed while importing _message

    更新于 2024年3月2日
  • #23

    the model learns very badly on cifar10 32*32

    更新于 2024年2月19日

核心特点

  • •Python

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言