This folder is copied from https://github.com/openai/improved-diffusion
My only change is in `improved_diffusion/gaussian_diffusion.py`: added function `p_sample_image_completion`.
Original readme:
# improved-diffusion
This is the codebase for [Improved Denoising Diffusion Probabilistic Models](https://arxiv.org/abs/2102.09672).
# Usage
This section of the README walks through how to train and sample from a model.
## Installation
Clone this repository and navigate to it in your terminal. Then run:
```
pip install -e .
```
This should install the `improved_diffusion` python package that the scripts depend on.
## Preparing Data
The training code reads images from a directory of image files. In the [datasets](datasets) folder, we have provided instructions/scripts for preparing these directories for ImageNet, LSUN bedrooms, and CIFAR-10.
For creating your own dataset, simply dump all of your images into a directory with ".jpg", ".jpeg", or ".png" extensions. If you wish to train a class-conditional model, name the files like "mylabel1_XXX.jpg", "mylabel2_YYY.jpg", etc., so that the data loader knows that "mylabel1" and "mylabel2" are the labels. Subdirectories will automatically be enumerated as well, so the images can be organized into a recursive structure (although the directory names will be ignored, and the underscore prefixes are used as names).
The images will automatically be scaled and center-cropped by the data-loading pipeline. Simply pass `--data_dir path/to/images` to the training script, and it will take care of the rest.
## Training
To train your model, you should first decide some hyperparameters. We will split up our hyperparameters into three groups: model architecture, diffusion process, and training flags. Here are some reasonable defaults for a baseline:
```
MODEL_FLAGS="--image_size 64 --num_channels 128 --num_res_blocks 3"
DIFFUSION_FLAGS="--diffusion_steps 4000 --noise_schedule linear"
TRAIN_FLAGS="--lr 1e-4 --batch_size 128"
```
Here are some changes we experiment with, and how to set them in the flags:
* **Learned sigmas:** add `--learn_sigma True` to `MODEL_FLAGS`
* **Cosine schedule:** change `--noise_schedule linear` to `--noise_schedule cosine`
* **Importance-sampled VLB:** add `--use_kl True` to `DIFFUSION_FLAGS` and add `--schedule_sampler loss-second-moment` to `TRAIN_FLAGS`.
* **Class-conditional:** add `--class_cond True` to `MODEL_FLAGS`.
Once you have setup your hyper-parameters, you can run an experiment like so:
```
python scripts/image_train.py --data_dir path/to/images $MODEL_FLAGS $DIFFUSION_FLAGS $TRAIN_FLAGS
```
You may also want to train in a distributed manner. In this case, run the same command with `mpiexec`:
```
mpiexec -n $NUM_GPUS python scripts/image_train.py --data_dir path/to/images $MODEL_FLAGS $DIFFUSION_FLAGS $TRAIN_FLAGS
```
When training in a distributed manner, you must manually divide the `--batch_size` argument by the number of ranks. In lieu of distributed training, you may use `--microbatch 16` (or `--microbatch 1` in extreme memory-limited cases) to reduce memory usage.
The logs and saved models will be written to a logging directory determined by the `OPENAI_LOGDIR` environment variable. If it is not set, then a temporary directory will be created in `/tmp`.
## Sampling
The above training script saves checkpoints to `.pt` files in the logging directory. These checkpoints will have names like `ema_0.9999_200000.pt` and `model200000.pt`. You will likely want to sample from the EMA models, since those produce much better samples.
Once you have a path to your model, you can generate a large batch of samples like so:
```
python scripts/image_sample.py --model_path /path/to/model.pt $MODEL_FLAGS $DIFFUSION_FLAGS
```
Again, this will save results to a logging directory. Samples are saved as a large `npz` file, where `arr_0` in the file is a large batch of samples.
Just like for training, you can run `image_sample.py` through MPI to use multiple GPUs and machines.
You can change the number of sampling steps using the `--timestep_respacing` argument. For example, `--timestep_respacing 250` uses 250 steps to sample. Passing `--timestep_respacing ddim250` is similar, but uses the uniform stride from the [DDIM paper](https://arxiv.org/abs/2010.02502) rather than our stride.
To sample using [DDIM](https://arxiv.org/abs/2010.02502), pass `--use_ddim True`.
## Models and Hyperparameters
This section includes model checkpoints and run flags for the main models in the paper.
Note that the batch sizes are specified for single-GPU training, even though most of these runs will not naturally fit on a single GPU. To address this, either set `--microbatch` to a small value (e.g. 4) to train on one GPU, or run with MPI and divide `--batch_size` by the number of GPUs.
Unconditional ImageNet-64 with our `L_hybrid` objective and cosine noise schedule [[checkpoint](https://openaipublic.blob.core.windows.net/diffusion/march-2021/imagenet64_uncond_100M_1500K.pt)]:
```bash
MODEL_FLAGS="--image_size 64 --num_channels 128 --num_res_blocks 3 --learn_sigma True"
DIFFUSION_FLAGS="--diffusion_steps 4000 --noise_schedule cosine"
TRAIN_FLAGS="--lr 1e-4 --batch_size 128"
```
Unconditional CIFAR-10 with our `L_hybrid` objective and cosine noise schedule [[checkpoint](https://openaipublic.blob.core.windows.net/diffusion/march-2021/cifar10_uncond_50M_500K.pt)]:
```bash
MODEL_FLAGS="--image_size 32 --num_channels 128 --num_res_blocks 3 --learn_sigma True --dropout 0.3"
DIFFUSION_FLAGS="--diffusion_steps 4000 --noise_schedule cosine"
TRAIN_FLAGS="--lr 1e-4 --batch_size 128"
```
Class-conditional ImageNet-64 model (270M parameters, trained for 250K iterations) [[checkpoint](https://openaipublic.blob.core.windows.net/diffusion/march-2021/imagenet64_cond_270M_250K.pt)]:
```bash
MODEL_FLAGS="--image_size 64 --num_channels 192 --num_res_blocks 3 --learn_sigma True --class_cond True"
DIFFUSION_FLAGS="--diffusion_steps 4000 --noise_schedule cosine --rescale_learned_sigmas False --rescale_timesteps False"
TRAIN_FLAGS="--lr 3e-4 --batch_size 2048"
```
Upsampling 256x256 model (280M parameters, trained for 500K iterations) [[checkpoint](https://openaipublic.blob.core.windows.net/diffusion/march-2021/upsample_cond_500K.pt)]:
```bash
MODEL_FLAGS="--num_channels 192 --num_res_blocks 2 --learn_sigma True --class_cond True"
DIFFUSION_FLAGS="--diffusion_steps 4000 --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False"
TRAIN_FLAGS="--lr 3e-4 --batch_size 256"
```
LSUN bedroom model (lr=1e-4) [[checkpoint](https://openaipublic.blob.core.windows.net/diffusion/march-2021/lsun_uncond_100M_1200K_bs128.pt)]:
```bash
MODEL_FLAGS="--image_size 256 --num_channels 128 --num_res_blocks 2 --num_heads 1 --learn_sigma True --use_scale_shift_norm False --attention_resolutions 16"
DIFFUSION_FLAGS="--diffusion_steps 1000 --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False"
TRAIN_FLAGS="--lr 1e-4 --batch_size 128"
```
LSUN bedroom model (lr=2e-5) [[checkpoint](https://openaipublic.blob.core.windows.net/diffusion/march-2021/lsun_uncond_100M_2400K_bs64.pt)]:
```bash
MODEL_FLAGS="--image_size 256 --num_channels 128 --num_res_blocks 2 --num_heads 1 --learn_sigma True --use_scale_shift_norm False --attention_resolutions 16"
DIFFUSION_FLAGS="--diffusion_steps 1000 --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False --use_scale_shift_norm False"
TRAIN_FLAGS="--lr 2e-5 --batch_size 128"
```
Unconditional ImageNet-64 with the `L_vlb` objective and cosine noise schedule [[checkpoint](https://openaipublic.blob.core.windows.net/diffusion/march-2021/imagenet64_uncond_vlb_100M_1500K.pt)]:
```bash
MODEL_FLAGS="--image_size 64 --num_channels 128 --num_res_blocks 3 --learn_sigma True"
DIFFUSION_FLAGS="--diffusion_steps 4000 --noise_schedule cosine --use_kl True"
TRAIN_FLAGS="--lr 1e-4 --batch_size 128 --schedule_sampler loss-second-moment"
```
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
毕业设计基于Pyqt5+扩散模型Diffusion Models的图像恢复项目Python源码+项目说明.zip 设计思路 环境准备: 确定Python的版本(推荐使用Python 3.6及以上)。 安装必要的库和框架,如NumPy用于数值计算,PIL或OpenCV用于图像处理,TensorFlow或PyTorch用于实现深度学习模型。 模块划分: 图像处理模块:负责读取、显示和保存图像,以及添加噪声等预处理操作。 扩散模型模块:实现基于扩散模型的图像恢复算法。 参数配置模块:管理用户输入的参数,控制扩散模型的行为。 用户界面模块:提供图形用户界面(GUI),让用户可以交互式地使用系统。 结果评估模块:计算并展示图像恢复质量的指标,如PSNR和SSIM。 图像处理模块: 使用OpenCV或PIL读取用户上传的原始图像。 实现一个函数来在图像上添加不同类型和强度的噪声。 提供保存和展示图像的功能。 扩散模型模块: 选择合适的深度学习框架,如PyTorch或TensorFlow,来构建扩散模型。 根据扩散模型的理论,实现模型的前向传播和反向传播过程。 实现模型训练过程,包括数据加载、模型更
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计基于Pyqt5+扩散模型Diffusion Models的图像恢复项目Python源码+项目说明.zip (106个子文件)
.gitignore 182B
.gitignore 55B
.gitignore 24B
DIffImageRecon.iml 318B
noisy_image.jpg 25.43MB
image2.jpg 6.66MB
image1.jpg 6.12MB
me+bird_result.jpg 506KB
doge_result.jpg 502KB
noisy_image_gaussian_50_20231220121414.jpg 69KB
noisy_image_gaussian_1.jpg 69KB
noise_java.jpg 69KB
noisy_image_gaussian_20_20231220121428.jpg 44KB
noisy_image_gaussian_20_20231229134741.jpg 44KB
noisy_image_gaussian_1_20231220121119.jpg 36KB
noisy_image_gaussian_1_20231220121014.jpg 36KB
noisy_image_gaussian_1_20231220120923.jpg 36KB
java.jpg 25KB
java.jpg 25KB
denoise_image1.jpg 24KB
gaussian_39_20231229142341.jpg 6KB
gaussian_24_20231229142353.jpg 5KB
gaussian_39_20231229140732.jpg 5KB
gaussian_38_20231229134913.jpg 5KB
gaussian_20_20231229142348.jpg 5KB
gaussian_37_20231229134808.jpg 5KB
gaussian_35_20231229134328.jpg 5KB
gaussian_35_20231229134510.jpg 5KB
gaussian_33_20231229135341.jpg 5KB
gaussian_37_20231229144322.jpg 4KB
gaussian_41_20231229143747.jpg 4KB
gaussian_22_20231229135549.jpg 4KB
gaussian_28_20231229144320.jpg 4KB
gaussian_21_20231229135140.jpg 4KB
gaussian_20_20231229144847.jpg 4KB
gaussian_25_20231229143742.jpg 4KB
gaussian_18_20231229144317.jpg 4KB
gaussian_0_20231229145146.jpg 3KB
gaussian_0_20231229145009.jpg 3KB
gaussian_10_20231229144841.jpg 3KB
resized_image1.jpg 3KB
gaussian_0_20231229150014.jpg 3KB
gaussian_0_20231229145752.jpg 3KB
LICENSE 1KB
README.md 8KB
README.md 5KB
README.md 3KB
README.md 2KB
UI.png 309KB
noisy_image_gaussian_1.png 148KB
noisy_image_gaussian_1.png 148KB
java.png 118KB
java.png 118KB
broken_java.png 108KB
broken_java_2.png 78KB
1702994966259.png 44KB
doge.png 31KB
final_image_diffusion_step_50.png 13KB
final_image_diffusion_step_732.png 13KB
final_image_diffusion_step_99.png 13KB
final_image_diffusion_step_288.png 13KB
final_image_diffusion_step_206.png 13KB
final_image_diffusion_step_1020.png 12KB
final_image_diffusion_step_815.png 11KB
final_image_diffusion_step_2097.png 11KB
final_image_diffusion_step_198.png 11KB
final_image_diffusion_step_519.png 11KB
final_image_diffusion_step_1012.png 10KB
gaussian_diffusion.py 33KB
unet.py 18KB
logger.py 14KB
train_util.py 12KB
main.py 12KB
script_util.py 8KB
resample.py 6KB
nn.py 5KB
respace.py 5KB
generate.py 4KB
upsample.py 4KB
image_datasets.py 4KB
ImageProcess.py 4KB
super_res_sample.py 4KB
image_sample.py 3KB
image_nll.py 3KB
super_res_train.py 3KB
losses.py 2KB
image_train.py 2KB
fp16_util.py 2KB
dist_util.py 2KB
DiffRecon.py 2KB
lsun_bedroom.py 2KB
image2npy.py 2KB
cifar10.py 944B
NAFNet.py 862B
ModelAgent.py 541B
visualize_samples.py 524B
setup.py 168B
__init__.py 74B
ImageProcess.cpython-39.pyc 3KB
ModelAgent.cpython-39.pyc 607B
共 106 条
- 1
- 2
资源评论
coderᅟᅠ
- 粉丝: 3844
- 资源: 1008
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功