[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-71066":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":14,"forks30d":14,"starsTrendScore":18,"compositeScore":19,"rankGlobal":8,"rankLanguage":8,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":8,"pushedAt":8,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":14,"starSnapshotCount":14,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},71066,"guided-diffusion","openai\u002Fguided-diffusion","openai",null,"Python",7389,912,130,109,0,7,9,22,21,82.58,"MIT License",false,"main",true,[],"2026-06-12 04:00:58","# guided-diffusion\n\nThis is the codebase for [Diffusion Models Beat GANS on Image Synthesis](http:\u002F\u002Farxiv.org\u002Fabs\u002F2105.05233).\n\nThis repository is based on [openai\u002Fimproved-diffusion](https:\u002F\u002Fgithub.com\u002Fopenai\u002Fimproved-diffusion), with modifications for classifier conditioning and architecture improvements.\n\n# Download pre-trained models\n\nWe have released checkpoints for the main models in the paper. Before using these models, please review the corresponding [model card](model-card.md) to understand the intended use and limitations of these models.\n\nHere are the download links for each model checkpoint:\n\n * 64x64 classifier: [64x64_classifier.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F64x64_classifier.pt)\n * 64x64 diffusion: [64x64_diffusion.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F64x64_diffusion.pt)\n * 128x128 classifier: [128x128_classifier.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F128x128_classifier.pt)\n * 128x128 diffusion: [128x128_diffusion.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F128x128_diffusion.pt)\n * 256x256 classifier: [256x256_classifier.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F256x256_classifier.pt)\n * 256x256 diffusion: [256x256_diffusion.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F256x256_diffusion.pt)\n * 256x256 diffusion (not class conditional): [256x256_diffusion_uncond.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F256x256_diffusion_uncond.pt)\n * 512x512 classifier: [512x512_classifier.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F512x512_classifier.pt)\n * 512x512 diffusion: [512x512_diffusion.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F512x512_diffusion.pt)\n * 64x64 -&gt; 256x256 upsampler: [64_256_upsampler.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F64_256_upsampler.pt)\n * 128x128 -&gt; 512x512 upsampler: [128_512_upsampler.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002F128_512_upsampler.pt)\n * LSUN bedroom: [lsun_bedroom.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002Flsun_bedroom.pt)\n * LSUN cat: [lsun_cat.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002Flsun_cat.pt)\n * LSUN horse: [lsun_horse.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002Flsun_horse.pt)\n * LSUN horse (no dropout): [lsun_horse_nodropout.pt](https:\u002F\u002Fopenaipublic.blob.core.windows.net\u002Fdiffusion\u002Fjul-2021\u002Flsun_horse_nodropout.pt)\n\n# Sampling from pre-trained models\n\nTo sample from these models, you can use the `classifier_sample.py`, `image_sample.py`, and `super_res_sample.py` scripts.\nHere, we provide flags for sampling from all of these models.\nWe assume that you have downloaded the relevant model checkpoints into a folder called `models\u002F`.\n\nFor these examples, we will generate 100 samples with batch size 4. Feel free to change these values.\n\n```\nSAMPLE_FLAGS=\"--batch_size 4 --num_samples 100 --timestep_respacing 250\"\n```\n\n## Classifier guidance\n\nNote for these sampling runs that you can set `--classifier_scale 0` to sample from the base diffusion model.\nYou may also use the `image_sample.py` script instead of `classifier_sample.py` in that case.\n\n * 64x64 model:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond True --diffusion_steps 1000 --dropout 0.1 --image_size 64 --learn_sigma True --noise_schedule cosine --num_channels 192 --num_head_channels 64 --num_res_blocks 3 --resblock_updown True --use_new_attention_order True --use_fp16 True --use_scale_shift_norm True\"\npython classifier_sample.py $MODEL_FLAGS --classifier_scale 1.0 --classifier_path models\u002F64x64_classifier.pt --classifier_depth 4 --model_path models\u002F64x64_diffusion.pt $SAMPLE_FLAGS\n```\n\n * 128x128 model:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond True --diffusion_steps 1000 --image_size 128 --learn_sigma True --noise_schedule linear --num_channels 256 --num_heads 4 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\npython classifier_sample.py $MODEL_FLAGS --classifier_scale 0.5 --classifier_path models\u002F128x128_classifier.pt --model_path models\u002F128x128_diffusion.pt $SAMPLE_FLAGS\n```\n\n * 256x256 model:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond True --diffusion_steps 1000 --image_size 256 --learn_sigma True --noise_schedule linear --num_channels 256 --num_head_channels 64 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\npython classifier_sample.py $MODEL_FLAGS --classifier_scale 1.0 --classifier_path models\u002F256x256_classifier.pt --model_path models\u002F256x256_diffusion.pt $SAMPLE_FLAGS\n```\n\n * 256x256 model (unconditional):\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond False --diffusion_steps 1000 --image_size 256 --learn_sigma True --noise_schedule linear --num_channels 256 --num_head_channels 64 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\npython classifier_sample.py $MODEL_FLAGS --classifier_scale 10.0 --classifier_path models\u002F256x256_classifier.pt --model_path models\u002F256x256_diffusion_uncond.pt $SAMPLE_FLAGS\n```\n\n * 512x512 model:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond True --diffusion_steps 1000 --image_size 512 --learn_sigma True --noise_schedule linear --num_channels 256 --num_head_channels 64 --num_res_blocks 2 --resblock_updown True --use_fp16 False --use_scale_shift_norm True\"\npython classifier_sample.py $MODEL_FLAGS --classifier_scale 4.0 --classifier_path models\u002F512x512_classifier.pt --model_path models\u002F512x512_diffusion.pt $SAMPLE_FLAGS\n```\n\n## Upsampling\n\nFor these runs, we assume you have some base samples in a file `64_samples.npz` or `128_samples.npz` for the two respective models.\n\n * 64 -&gt; 256:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond True --diffusion_steps 1000 --large_size 256  --small_size 64 --learn_sigma True --noise_schedule linear --num_channels 192 --num_heads 4 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\npython super_res_sample.py $MODEL_FLAGS --model_path models\u002F64_256_upsampler.pt --base_samples 64_samples.npz $SAMPLE_FLAGS\n```\n\n * 128 -&gt; 512:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16 --class_cond True --diffusion_steps 1000 --large_size 512 --small_size 128 --learn_sigma True --noise_schedule linear --num_channels 192 --num_head_channels 64 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\npython super_res_sample.py $MODEL_FLAGS --model_path models\u002F128_512_upsampler.pt $SAMPLE_FLAGS --base_samples 128_samples.npz\n```\n\n## LSUN models\n\nThese models are class-unconditional and correspond to a single LSUN class. Here, we show how to sample from `lsun_bedroom.pt`, but the other two LSUN checkpoints should work as well:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond False --diffusion_steps 1000 --dropout 0.1 --image_size 256 --learn_sigma True --noise_schedule linear --num_channels 256 --num_head_channels 64 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\npython image_sample.py $MODEL_FLAGS --model_path models\u002Flsun_bedroom.pt $SAMPLE_FLAGS\n```\n\nYou can sample from `lsun_horse_nodropout.pt` by changing the dropout flag:\n\n```\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond False --diffusion_steps 1000 --dropout 0.0 --image_size 256 --learn_sigma True --noise_schedule linear --num_channels 256 --num_head_channels 64 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\npython image_sample.py $MODEL_FLAGS --model_path models\u002Flsun_horse_nodropout.pt $SAMPLE_FLAGS\n```\n\nNote that for these models, the best samples result from using 1000 timesteps:\n\n```\nSAMPLE_FLAGS=\"--batch_size 4 --num_samples 100 --timestep_respacing 1000\"\n```\n\n# Results\n\nThis table summarizes our ImageNet results for pure guided diffusion models:\n\n| Dataset          | FID  | Precision | Recall |\n|------------------|------|-----------|--------|\n| ImageNet 64x64   | 2.07 | 0.74      | 0.63   |\n| ImageNet 128x128 | 2.97 | 0.78      | 0.59   |\n| ImageNet 256x256 | 4.59 | 0.82      | 0.52   |\n| ImageNet 512x512 | 7.72 | 0.87      | 0.42   |\n\nThis table shows the best results for high resolutions when using upsampling and guidance together:\n\n| Dataset          | FID  | Precision | Recall |\n|------------------|------|-----------|--------|\n| ImageNet 256x256 | 3.94 | 0.83      | 0.53   |\n| ImageNet 512x512 | 3.85 | 0.84      | 0.53   |\n\nFinally, here are the unguided results on individual LSUN classes:\n\n| Dataset      | FID  | Precision | Recall |\n|--------------|------|-----------|--------|\n| LSUN Bedroom | 1.90 | 0.66      | 0.51   |\n| LSUN Cat     | 5.57 | 0.63      | 0.52   |\n| LSUN Horse   | 2.57 | 0.71      | 0.55   |\n\n# Training models\n\nTraining diffusion models is described in the [parent repository](https:\u002F\u002Fgithub.com\u002Fopenai\u002Fimproved-diffusion). Training a classifier is similar. We assume you have put training hyperparameters into a `TRAIN_FLAGS` variable, and classifier hyperparameters into a `CLASSIFIER_FLAGS` variable. Then you can run:\n\n```\nmpiexec -n N python scripts\u002Fclassifier_train.py --data_dir path\u002Fto\u002Fimagenet $TRAIN_FLAGS $CLASSIFIER_FLAGS\n```\n\nMake sure to divide the batch size in `TRAIN_FLAGS` by the number of MPI processes you are using.\n\nHere are flags for training the 128x128 classifier. You can modify these for training classifiers at other resolutions:\n\n```sh\nTRAIN_FLAGS=\"--iterations 300000 --anneal_lr True --batch_size 256 --lr 3e-4 --save_interval 10000 --weight_decay 0.05\"\nCLASSIFIER_FLAGS=\"--image_size 128 --classifier_attention_resolutions 32,16,8 --classifier_depth 2 --classifier_width 128 --classifier_pool attention --classifier_resblock_updown True --classifier_use_scale_shift_norm True\"\n```\n\nFor sampling from a 128x128 classifier-guided model, 25 step DDIM:\n\n```sh\nMODEL_FLAGS=\"--attention_resolutions 32,16,8 --class_cond True --image_size 128 --learn_sigma True --num_channels 256 --num_heads 4 --num_res_blocks 2 --resblock_updown True --use_fp16 True --use_scale_shift_norm True\"\nCLASSIFIER_FLAGS=\"--image_size 128 --classifier_attention_resolutions 32,16,8 --classifier_depth 2 --classifier_width 128 --classifier_pool attention --classifier_resblock_updown True --classifier_use_scale_shift_norm True --classifier_scale 1.0 --classifier_use_fp16 True\"\nSAMPLE_FLAGS=\"--batch_size 4 --num_samples 50000 --timestep_respacing ddim25 --use_ddim True\"\nmpiexec -n N python scripts\u002Fclassifier_sample.py \\\n    --model_path \u002Fpath\u002Fto\u002Fmodel.pt \\\n    --classifier_path path\u002Fto\u002Fclassifier.pt \\\n    $MODEL_FLAGS $CLASSIFIER_FLAGS $SAMPLE_FLAGS\n```\n\nTo sample for 250 timesteps without DDIM, replace `--timestep_respacing ddim25` to `--timestep_respacing 250`, and replace `--use_ddim True` with `--use_ddim False`.\n","guided-diffusion 是一个用于图像合成的代码库，基于扩散模型实现，其性能优于生成对抗网络（GANs）。该项目的核心功能包括通过条件分类器和架构改进来生成高质量的图像。它支持多种分辨率下的图像生成，并提供了预训练模型供用户下载使用。此外，还包含上采样模型，能够将低分辨率图像转换为高分辨率图像。此项目适合需要进行高质量图像生成或图像增强的研究者和开发者使用，尤其适用于那些对图像细节有较高要求的应用场景。",2,"2026-06-11 03:35:43","high_star"]