juraam/stable-diffusion-from-scratch
关于
使用 PyTorch 实现 Stable Diffusion
其他项目实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Stable Diffusion from scratch
Little intro
It is an educational repository with a purpose to understand how Stable Diffusion and Diffusion models work.
Why did I decide to create this repo?
I started this project with the purpose to understand how Stable Diffusion works and what math it uses. I've read a lot of articles with math explanation and code implementation, but I didn't find something which bridges them in the one place.
Do you need to have a degree to understand math?
It depends on level you have, but I tried to write formulas with all important details and links to resources, which you can read if you get stuck.
How better to read this repo?
Latent Diffusion models based on Diffusion models(or Simple Diffusion). It's the heart of Stable Diffusion and it's really important to understand what diffusion is, how it works and how it's possible to make any picture in our imagination from just a noise. These are my suggestions about steps to understand the information.
Start with Math Explanation.ipynb . This is my explanation of math behind diffusion models, based on great articles of other authors and of course my own research. It took two weeks to understand all details of formulas, but I tried to give the information easily.
In this repo you can look at implementation of two different diffusion models: Conditional Diffusion and Simple Diffusion. The Conditional is similar to Stable Diffusion, but it works only number(number means class or digit) input, not text prompts. So it's better to start from Simple Diffusion models.
For experiments I have created two jupyter notebooks:
- For training and sampling Simple Diffusion
- For training and sampling Conditional Diffusion.
Code
INSTALL REQUIREMENTS
To start working with code, please download all required dependencies:
pip install -r requirements.txt
DOWNLOAD MODELS
I put all models to huggingfase, so to download models with lfs, just run:
git clone https://huggingface.co/juramoshkov/ddpm models
SAMPLING
If you want to get random samples, open Simple diffusion. Or if you want to control a generation with input as class, open Conditional diffusion.
All jupyter notebooks have PATH_TO_READY_MODEL, which you should fill to skip the training phase.
TRAINING
If you want to train a simple diffusion, open Simple diffusion, choose dataset (cifar10 or mnist) and run all cells.
If you want to train a conditional diffusion, open Conditional diffusion, choose dataset (cifar10 or mnist) and run all cells.
Results of my model
| Model | FID (CIFAR 10) |
|---|---|
| Original Diffusion | 3.17 |
| My Diffusion | 30 |

References
- https://lilianweng.github.io/posts/2021-07-11-diffusion-models/
- https://calvinyluo.com/2022/08/26/diffusion-tutorial.html#mjx-eqn%3Aeq%3A79
- https://arxiv.org/abs/2006.11239
- https://arxiv.org/abs/2207.12598
- https://github.com/TeaPearce/Conditional_Diffusion_MNIST
- https://github.com/cloneofsimo/minDiffusion
- https://theaisummer.com/diffusion-models/
- https://yang-song.net/blog/2021/score/
探索相关项目
加载中…