[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-yang-song--score_sde":3,"tool-yang-song--score_sde":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":81,"owner_twitter":81,"owner_website":82,"owner_url":83,"languages":84,"stars":93,"forks":94,"last_commit_at":95,"license":96,"difficulty_score":10,"env_os":97,"env_gpu":98,"env_ram":97,"env_deps":99,"category_tags":110,"github_topics":111,"view_count":23,"oss_zip_url":81,"oss_zip_packed_at":81,"status":16,"created_at":120,"updated_at":121,"faqs":122,"releases":153},2807,"yang-song\u002Fscore_sde","score_sde","Official code for Score-Based Generative Modeling through Stochastic Differential Equations (ICLR 2021, Oral)","score_sde 是谷歌研究团队开源的生成式建模代码库，核心基于“通过随机微分方程进行基于分数的生成建模”这一前沿理论。它旨在解决传统生成模型在样本质量、似然计算精确度以及条件生成能力（如图像修复、上色）上的局限。通过将数据分布到噪声的过程建模为连续的随机微分方程（SDE），score_sde 提供了一个统一框架，不仅涵盖了 NCSN、DDPM 等经典模型，还支持更高效的采样算法和潜在的编码操作。\n\n该项目特别适合人工智能研究人员和深度学习开发者使用。对于希望深入理解扩散模型原理、复现顶级会议（ICLR 2021 Oral）成果或开发新型生成算法的专业人士而言，这是一个极具价值的参考实现。代码库设计模块化，易于扩展新的 SDE 类型、预测器或校正器，并提供了 JAX 和 PyTorch 两个版本以适应不同的硬件资源与速度需求。其技术亮点在于实现了无条件下 CIFAR-10 数据集上 FID 低至 2.20 的卓越生成质量，并支持高分辨率图像生成及精确的似然评估，为探索生成式 AI 的边界提供了坚实的技术底座。","# Score-Based Generative Modeling through Stochastic Differential Equations\n\n[![PWC](https:\u002F\u002Fimg.shields.io\u002Fendpoint.svg?url=https:\u002F\u002Fpaperswithcode.com\u002Fbadge\u002Fscore-based-generative-modeling-through-1\u002Fimage-generation-on-cifar-10)](https:\u002F\u002Fpaperswithcode.com\u002Fsota\u002Fimage-generation-on-cifar-10?p=score-based-generative-modeling-through-1)\n\nThis repo contains the official implementation for the paper [Score-Based Generative Modeling through Stochastic Differential Equations](https:\u002F\u002Fopenreview.net\u002Fforum?id=PxTIG12RRHS)\n\nby [Yang Song](https:\u002F\u002Fyang-song.github.io), [Jascha Sohl-Dickstein](http:\u002F\u002Fwww.sohldickstein.com\u002F), [Diederik P. Kingma](http:\u002F\u002Fdpkingma.com\u002F), [Abhishek Kumar](http:\u002F\u002Fusers.umiacs.umd.edu\u002F~abhishek\u002F), [Stefano Ermon](https:\u002F\u002Fcs.stanford.edu\u002F~ermon\u002F), and [Ben Poole](https:\u002F\u002Fcs.stanford.edu\u002F~poole\u002F)\n\n--------------------\n\nWe propose a unified framework that generalizes and improves previous work on score-based generative models through the lens of stochastic differential equations (SDEs). In particular, we can transform data to a simple noise distribution with a continuous-time stochastic process described by an SDE. This SDE can be reversed for sample generation if we know the score of the marginal distributions at each intermediate time step, which can be estimated with score matching. The basic idea is captured in the figure below:\n\n![schematic](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_5c2b74e6c4e8.jpg)\n\nOur work enables a better understanding of existing approaches,  new sampling algorithms, exact likelihood computation, uniquely identifiable encoding, latent code manipulation, and brings new conditional generation abilities (including but not limited to class-conditional generation, inpainting and colorization) to the family of score-based generative models.\n\nAll combined, we achieved an FID of **2.20** and an Inception score of **9.89** for unconditional generation on CIFAR-10, as well as high-fidelity generation of **1024px** Celeba-HQ images (samples below). In addition, we obtained a likelihood value of **2.99** bits\u002Fdim on uniformly dequantized CIFAR-10 images.\n\n![FFHQ samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_84ff65144675.jpg)\n\n## What does this code do?\nAside from the **NCSN++** and **DDPM++** models in our paper, this codebase also re-implements many previous score-based models in one place, including **NCSN** from [Generative Modeling by Estimating Gradients of the Data Distribution](https:\u002F\u002Farxiv.org\u002Fabs\u002F1907.05600), **NCSNv2** from [Improved Techniques for Training Score-Based Generative Models](https:\u002F\u002Farxiv.org\u002Fabs\u002F2006.09011), and **DDPM** from [Denoising Diffusion Probabilistic Models](https:\u002F\u002Farxiv.org\u002Fabs\u002F2006.11239). \n\nIt supports training new models, evaluating the sample quality and likelihoods of existing models. We carefully designed the code to be modular and easily extensible to new SDEs, predictors, or correctors.\n\n## PyTorch version\n\nPlease find a PyTorch implementation [here](https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde_pytorch), which supports everything except class-conditional generation with a pre-trained classifier.\n\n###  JAX vs. PyTorch\n\nIn general, the PyTorch version consumes less memory but also runs slower than JAX. Here is a benchmark on training an NCSN++ cont. model with VE SDE. Hardware is 4x Nvidia Tesla V100 GPUs (32GB)\n| Framework | Time (second per step) | Memory usage in total (GB) |\n|:----:|:----:|:----:|\n|PyTorch | 0.56 | 20.6|\n|JAX (`n_jitted_steps=1`)| 0.30 | 29.7 |\n|JAX (`n_jitted_steps=5`) | 0.20 | 74.8|\n\n## How to run the code\n\n### Dependencies\n\nRun the following to install a subset of necessary python packages for our code\n```sh\npip install -r requirements.txt\n```\n\n### Stats files for quantitative evaluation\n\nWe provide the stats file for CIFAR-10. You can download [`cifar10_stats.npz`](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1fXgBupLzThTGLLsiYCHRQJixuDsR1bSI\u002Fview?usp=sharing)  and save it to `assets\u002Fstats\u002F`. Check out [#5](https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fpull\u002F5) on how to compute this stats file for new datasets.\n\n### Usage\n\nTrain and evaluate our models through `main.py`.\n\n```sh\nmain.py:\n  --config: Training configuration.\n    (default: 'None')\n  --eval_folder: The folder name for storing evaluation results\n    (default: 'eval')\n  --mode: \u003Ctrain|eval>: Running mode: train or eval\n  --workdir: Working directory\n```\n\n* `config` is the path to the config file. Our prescribed config files are provided in `configs\u002F`. They are formatted according to [`ml_collections`](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fml_collections) and should be quite self-explanatory.\n\n  **Naming conventions of config files**: the path of a config file is a combination of the following dimensions:\n  *  dataset: One of `cifar10`, `celeba`, `celebahq`, `celebahq_256`, `ffhq_256`, `celebahq`, `ffhq`.\n  * model: One of `ncsn`, `ncsnv2`, `ncsnpp`, `ddpm`, `ddpmpp`.\n  * continuous: train the model with continuously sampled time steps. \n\n*  `workdir` is the path that stores all artifacts of one experiment, like checkpoints, samples, and evaluation results.\n\n* `eval_folder` is the name of a subfolder in `workdir` that stores all artifacts of the evaluation process, like meta checkpoints for pre-emption prevention, image samples, and numpy dumps of quantitative results.\n\n* `mode` is either \"train\" or \"eval\". When set to \"train\", it starts the training of a new model, or resumes the training of an old model if its meta-checkpoints (for resuming running after pre-emption in a cloud environment) exist in `workdir\u002Fcheckpoints-meta` . When set to \"eval\", it can do an arbitrary combination of the following\n\n  * Evaluate the loss function on the test \u002F validation dataset.\n\n  * Generate a fixed number of samples and compute its Inception score, FID, or KID. Prior to evaluation, stats files must have already been downloaded\u002Fcomputed and stored in `assets\u002Fstats`.\n\n  * Compute the log-likelihood on the training or test dataset.\n\n  These functionalities can be configured through config files, or more conveniently, through the command-line support of the `ml_collections` package. For example, to generate samples and evaluate sample quality, supply the  `--config.eval.enable_sampling` flag; to compute log-likelihoods, supply the `--config.eval.enable_bpd` flag, and specify `--config.eval.dataset=train\u002Ftest` to indicate whether to compute the likelihoods on the training or test dataset.\n\n## How to extend the code\n* **New SDEs**: inherent the `sde_lib.SDE` abstract class and implement all abstract methods. The `discretize()` method is optional and the default is Euler-Maruyama discretization. Existing sampling methods and likelihood computation will automatically work for this new SDE.\n* **New predictors**: inherent the `sampling.Predictor` abstract class, implement the `update_fn` abstract method, and register its name with `@register_predictor`. The new predictor can be directly used in `sampling.get_pc_sampler` for Predictor-Corrector sampling, and all other controllable generation methods in `controllable_generation.py`.\n* **New correctors**: inherent the `sampling.Corrector` abstract class, implement the `update_fn` abstract method, and register its name with `@register_corrector`. The new corrector can be directly used in `sampling.get_pc_sampler`, and all other controllable generation methods in `controllable_generation.py`.\n\n## Pretrained checkpoints\nAll checkpoints are provided in this [Google drive](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1RAG8qpOTURkrqXKwdAR1d6cU9rwoQYnH?usp=sharing).\n\n**Instructions**: You may find two checkpoints for some models. The first checkpoint (with a smaller number) is the one that we reported FID scores in our paper's Table 3 (also corresponding to the FID and IS columns in the table below). The second checkpoint (with a larger number) is the one that we reported likelihood values and FIDs of black-box ODE samplers in our paper's Table 2 (also FID(ODE) and NNL (bits\u002Fdim) columns in the table below). The former corresponds to the smallest FID during the course of training (every 50k iterations). The later is the last checkpoint during training.\n\nPer Google's policy, we cannot release our original CelebA and CelebA-HQ checkpoints. That said, I have re-trained models on FFHQ 1024px, FFHQ 256px and CelebA-HQ 256px with personal resources, and they achieved similar performance to our internal checkpoints. \n\nHere is a detailed list of checkpoints and their results reported in the paper. **FID (ODE)** corresponds to the sample quality of black-box ODE solver applied to the probability flow ODE.\n\n| Checkpoint path | FID | IS | FID (ODE) | NNL (bits\u002Fdim) |\n|:----------|:-------:|:----------:|:----------:|:----------:|\n| [`ve\u002Fcifar10_ncsnpp\u002F`](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1fXgBupLzThTGLLsiYCHRQJixuDsR1bSI\u002Fview?usp=sharing) |  2.45 | 9.73 | - | - |\n| [`ve\u002Fcifar10_ncsnpp_continuous\u002F`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1Ko7hOCMIM6yFShJCIU4LBsF0sfjWuafa?usp=sharing) | 2.38 | 9.83 | - | - |\n| [`ve\u002Fcifar10_ncsnpp_deep_continuous\u002F`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1rvziylUQiXWyOF1jVhGxzgGmtp1oTNT5?usp=sharing) | **2.20** | **9.89** | - | - |\n| [`vp\u002Fcifar10_ddpm\u002F`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1vzeGmgCj95_04MTDh6aa5BI098Q8ybO5?usp=sharing) | 3.24 | - | 3.37 | 3.28 |\n| [`vp\u002Fcifar10_ddpm_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1qTZXghJxo8t5gTN52FuAWO6YABu2ElTN?usp=sharing) | - | - | 3.69| 3.21 |\n| [`vp\u002Fcifar10_ddpmpp`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F14AhlnhRryO7XqjrHEtHZRcb_v_bEUd7X?usp=sharing) | 2.78 | 9.64 | - | - |\n| [`vp\u002Fcifar10_ddpmpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1ikbUY_K4Rc2-lPz7baPxdEXtx76Xn5Ov?usp=sharing) | 2.55 | 9.58 | 3.93 | 3.16 |\n| [`vp\u002Fcifar10_ddpmpp_deep_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1F74y6G_AGqPw8DG5uhdO_Kf9DCX1jKfL?usp=sharing) | 2.41 | 9.68 | 3.08 | 3.13 |\n| [`subvp\u002Fcifar10_ddpm_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1Qk6SaMq3EFnMH1rr2OdFZU5IzDKYbskh?usp=sharing) | - | - | 3.56 | 3.05 |\n| [`subvp\u002Fcifar10_ddpmpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1tDz-jQ-tD5A_UjB1gxzoofo07W0LC1aO?usp=sharing) | 2.61 | 9.56 | 3.16 | 3.02 |\n| [`subvp\u002Fcifar10_ddpmpp_deep_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1qjKjuZULYu2uN0sP79yTPkOhEvUPhYnU?usp=sharing) | 2.41 | 9.57 | **2.92** | **2.99** |\n\n| Checkpoint path | Samples |\n|:-----|:------:|\n| [`ve\u002Fbedroom_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1tcvR65amqrD65Hn0EPlZqNPiCZh2rg4M?usp=sharing) | ![bedroom_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_772513bfb9ae.jpeg) |\n| [`ve\u002Fchurch_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1h8JayORNKTo8pCCLMr0ZDJkM7U87dKM5?usp=sharing) | ![church_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_ecc24b3b908b.jpeg) |\n| [`ve\u002Fffhq_1024_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1GwcthBS4Ry54eA_fIg1hOCfThQ6I3u1L?usp=sharing) |![ffhq_1024](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_c4f07a106670.jpeg)|\n| [`ve\u002Fffhq_256_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1-2tUJ3tOU2AruyMYPB33x1aWVOQMSygM?usp=sharing) |![ffhq_256_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_caa2de1b67b1.jpg)|\n| [`ve\u002Fcelebahq_256_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1LK2bGXpZBzJKLCcL_NfUKsr8dxT8XVh5?usp=sharing) |![celebahq_256_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_358ef1dc50a7.jpg)|\n\n\n\n\n## Demonstrations and tutorials\n| Link | Description|\n|:----:|:-----|\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1dRR_0gNRmfLtPavX2APzUggBuXyjWW55?usp=sharing)  | Load our pretrained checkpoints and play with sampling, likelihood computation, and controllable synthesis (JAX + FLAX)|\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F17lTrPLTt_0EDXa4hkbHmbAFQEkpRDZnh?usp=sharing) | Load our pretrained checkpoints and play with sampling, likelihood computation, and controllable synthesis (PyTorch) |\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1SeXMpILhkJPjXUaesvzEhc3Ke6Zl_zxJ?usp=sharing)  | Tutorial of score-based generative models in JAX + FLAX |\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F120kYYBOVa1i0TD85RjlEkFjaWDxSFUx3?usp=sharing)| Tutorial of score-based generative models in PyTorch |\n\n\n## Tips\n* When using the JAX codebase, you can jit multiple training steps together to improve training speed at the cost of more memory usage. This can be set via `config.training.n_jitted_steps`. For CIFAR-10, we recommend using `config.training.n_jitted_steps=5` when your GPU\u002FTPU has sufficient memory; otherwise we recommend using `config.training.n_jitted_steps=1`. Our current implementation requires `config.training.log_freq` to be dividable by `n_jitted_steps` for logging and checkpointing to work normally.\n* The `snr` (signal-to-noise ratio) parameter of `LangevinCorrector` somewhat behaves like a temperature parameter. Larger `snr` typically results in smoother samples, while smaller `snr` gives more diverse but lower quality samples. Typical values of `snr` is `0.05 - 0.2`, and it requires tuning to strike the sweet spot.\n* For VE SDEs, we recommend choosing `config.model.sigma_max` to be the maximum pairwise distance between data samples in the training dataset.\n\n## References\n\nIf you find the code useful for your research, please consider citing\n```bib\n@inproceedings{\n  song2021scorebased,\n  title={Score-Based Generative Modeling through Stochastic Differential Equations},\n  author={Yang Song and Jascha Sohl-Dickstein and Diederik P Kingma and Abhishek Kumar and Stefano Ermon and Ben Poole},\n  booktitle={International Conference on Learning Representations},\n  year={2021},\n  url={https:\u002F\u002Fopenreview.net\u002Fforum?id=PxTIG12RRHS}\n}\n```\n\nThis work is built upon some previous papers which might also interest you:\n\n* Song, Yang, and Stefano Ermon. \"Generative Modeling by Estimating Gradients of the Data Distribution.\" *Proceedings of the 33rd Annual Conference on Neural Information Processing Systems*. 2019.\n* Song, Yang, and Stefano Ermon. \"Improved techniques for training score-based generative models.\" *Proceedings of the 34th Annual Conference on Neural Information Processing Systems*. 2020.\n* Ho, Jonathan, Ajay Jain, and Pieter Abbeel. \"Denoising diffusion probabilistic models.\" *Proceedings of the 34th Annual Conference on Neural Information Processing Systems*. 2020.\n\n","# 基于分数的生成模型：通过随机微分方程\n\n[![PWC](https:\u002F\u002Fimg.shields.io\u002Fendpoint.svg?url=https:\u002F\u002Fpaperswithcode.com\u002Fbadge\u002Fscore-based-generative-modeling-through-1\u002Fimage-generation-on-cifar-10)](https:\u002F\u002Fpaperswithcode.com\u002Fsota\u002Fimage-generation-on-cifar-10?p=score-based-generative-modeling-through-1)\n\n本仓库包含论文《基于分数的生成模型：通过随机微分方程》的官方实现，该论文由Yang Song、Jascha Sohl-Dickstein、Diederik P. Kingma、Abhishek Kumar、Stefano Ermon和Ben Poole共同撰写。\n\n--------------------\n\n我们提出了一种统一的框架，通过随机微分方程（SDE）的视角，对先前基于分数的生成模型工作进行了推广和改进。具体而言，我们可以利用由SDE描述的连续时间随机过程，将数据转换为简单的噪声分布。如果已知每个中间时间步长上边缘分布的分数函数，就可以反转这一SDE来生成样本，而这些分数函数则可通过分数匹配方法进行估计。其基本思想如图所示：\n\n![示意图](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_5c2b74e6c4e8.jpg)\n\n我们的工作不仅有助于更好地理解现有方法，还带来了新的采样算法、精确的似然计算、唯一可识别的编码以及潜在代码操控能力，并为基于分数的生成模型家族增添了新的条件生成能力（包括但不限于类别条件生成、图像修复和彩色化）。综合来看，在CIFAR-10数据集上的无条件生成任务中，我们取得了2.20的FID值和9.89的Inception得分；同时，还能高质量地生成1024像素的Celeba-HQ图像（见下方样本）。此外，在均匀去量化后的CIFAR-10图像上，我们还获得了2.99比特\u002F维度的似然值。\n\n![FFHQ样本](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_84ff65144675.jpg)\n\n## 该代码的功能是什么？\n除了我们论文中的NCSN++和DDPM++模型外，本代码库还在一处重新实现了许多先前的基于分数的模型，包括来自《通过估计数据分布的梯度进行生成建模》一文的NCSN、来自《改进训练基于分数的生成模型的技术》一文的NCSNv2，以及来自《去噪扩散概率模型》一文的DDPM。\n\n该代码支持训练新模型，也支持评估现有模型的样本质量和似然值。我们精心设计了代码结构，使其具有模块化特性，便于扩展到新的SDE、预测器或校正器。\n\n## PyTorch版本\n\n请在此处查看PyTorch实现：[https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde_pytorch]，该实现支持除使用预训练分类器进行类别条件生成之外的所有功能。\n\n### JAX与PyTorch对比\n一般来说，PyTorch版本的内存消耗较少，但运行速度比JAX慢。以下是在4块Nvidia Tesla V100 GPU（32GB）硬件上训练NCSN++连续模型时的基准测试结果：\n\n| 框架       | 每步耗时（秒） | 总内存占用（GB） |\n|------------|----------------|------------------|\n| PyTorch    | 0.56           | 20.6             |\n| JAX (`n_jitted_steps=1`) | 0.30           | 29.7             |\n| JAX (`n_jitted_steps=5`) | 0.20           | 74.8             |\n\n## 如何运行代码\n\n### 依赖项\n运行以下命令以安装本代码所需的部分Python包：\n```sh\npip install -r requirements.txt\n```\n\n### 定量评估用统计文件\n我们提供了CIFAR-10数据集的统计文件。您可以下载[`cifar10_stats.npz`](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1fXgBupLzThTGLLsiYCHRQJixuDsR1bSI\u002Fview?usp=sharing)，并将其保存至`assets\u002Fstats\u002F`目录下。有关如何为新数据集计算此类统计文件，请参阅[#5](https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fpull\u002F5)。\n\n### 使用方法\n通过`main.py`训练和评估我们的模型。\n\n```sh\nmain.py:\n  --config: 训练配置文件。\n    （默认值：'None'）\n  --eval_folder: 存储评估结果的文件夹名称\n    （默认值：'eval'）\n  --mode: \u003Ctrain|eval>：运行模式——训练或评估\n  --workdir: 工作目录\n```\n\n* `config`是配置文件的路径。我们提供的预设配置文件位于`configs\u002F`目录中，它们按照`ml_collections`格式编写，应该相当直观易懂。\n\n  **配置文件命名规则**：配置文件路径由以下几个维度组合而成：\n  * 数据集：可以是`cifar10`、`celeba`、`celebahq`、`celebahq_256`、`ffhq_256`、`celebahq`或`ffhq`之一。\n  * 模型：可以是`ncsn`、`ncsnv2`、`ncsnpp`、`ddpm`或`ddpmpp`之一。\n  * 连续性：表示是否使用连续采样的时间步长来训练模型。\n\n* `workdir`是用于存储一次实验所有产物的路径，例如检查点、样本和评估结果等。\n\n* `eval_folder`是`workdir`下的一个子文件夹名称，用于存放评估过程中产生的所有成果，比如防止中断的元检查点、图像样本以及定量结果的numpy文件等。\n\n* `mode`可以是“train”或“eval”。当设置为“train”时，将开始训练新模型；若`workdir\u002Fcheckpoints-meta`目录下存在用于在云环境中恢复运行的元检查点，则会继续之前未完成的训练。当设置为“eval”时，可以执行以下任意组合的操作：\n\n  * 在测试或验证数据集上评估损失函数。\n  * 生成固定数量的样本，并计算其Inception得分、FID或KID值。在评估之前，必须先下载或计算好统计文件，并将其存放在`assets\u002Fstats`目录中。\n  * 在训练或测试数据集上计算对数似然。\n\n以上功能既可以通过配置文件进行设置，也可以更便捷地通过`ml_collections`包提供的命令行支持来实现。例如，要生成样本并评估样本质量，只需添加`--config.eval.enable_sampling`标志；若要计算对数似然，则需添加`--config.eval.enable_bpd`标志，并指定`--config.eval.dataset=train\u002Ftest`以表明是在训练集还是测试集上计算似然值。\n\n## 如何扩展代码\n* **新的 SDE**：继承 `sde_lib.SDE` 抽象类，并实现所有抽象方法。`discretize()` 方法是可选的，默认使用欧拉-丸山离散化。现有的采样方法和似然计算将自动适用于这个新的 SDE。\n* **新的预测器**：继承 `sampling.Predictor` 抽象类，实现 `update_fn` 抽象方法，并使用 `@register_predictor` 注册其名称。新预测器可以直接用于 `sampling.get_pc_sampler` 中的预测-校正采样，以及 `controllable_generation.py` 中的所有其他可控生成方法。\n* **新的校正器**：继承 `sampling.Corrector` 抽象类，实现 `update_fn` 抽象方法，并使用 `@register_corrector` 注册其名称。新校正器可以直接用于 `sampling.get_pc_sampler`，以及 `controllable_generation.py` 中的所有其他可控生成方法。\n\n## 预训练检查点\n所有检查点都提供在这个 [Google Drive](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1RAG8qpOTURkrqXKwdAR1d6cU9rwoQYnH?usp=sharing) 中。\n\n**说明**：对于某些模型，您可能会找到两个检查点。第一个检查点（编号较小）是我们论文表3中报告 FID 分数的检查点（也对应于下表中的 FID 和 IS 列）。第二个检查点（编号较大）是我们论文表2中报告黑箱 ODE 采样器的似然值和 FID 的检查点（也对应于下表中的 FID(ODE) 和 NNL (bits\u002Fdim) 列）。前者对应于训练过程中每 50k 次迭代时达到的最小 FID，后者则是训练结束时的最后一个检查点。\n\n根据 Google 的政策，我们无法发布原始的 CelebA 和 CelebA-HQ 检查点。不过，我已利用个人资源在 FFHQ 1024px、FFHQ 256px 和 CelebA-HQ 256px 数据集上重新训练了模型，这些模型的表现与我们的内部检查点相当。\n\n以下是论文中报告的检查点及其结果的详细列表。**FID (ODE)** 对应于应用于概率流 ODE 的黑箱 ODE 求解器的样本质量。\n\n| 检查点路径 | FID | IS | FID (ODE) | NNL (bits\u002Fdim) |\n|:----------|:-------:|:----------:|:----------:|:----------:|\n| [`ve\u002Fcifar10_ncsnpp\u002F`](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1fXgBupLzThTGLLsiYCHRQJixuDsR1bSI\u002Fview?usp=sharing) |  2.45 | 9.73 | - | - |\n| [`ve\u002Fcifar10_ncsnpp_continuous\u002F`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1Ko7hOCMIM6yFShJCIU4LBsF0sfjWuafa?usp=sharing) | 2.38 | 9.83 | - | - |\n| [`ve\u002Fcifar10_ncsnpp_deep_continuous\u002F`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1rvziylUQiXWyOF1jVhGxzgGmtp1oTNT5?usp=sharing) | **2.20** | **9.89** | - | - |\n| [`vp\u002Fcifar10_ddpm\u002F`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1vzeGmgCj95_04MTDh6aa5BI098Q8ybO5?usp=sharing) | 3.24 | - | 3.37 | 3.28 |\n| [`vp\u002Fcifar10_ddpm_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1qTZXghJxo8t5gTN52FuAWO6YABu2ElTN?usp=sharing) | - | - | 3.69| 3.21 |\n| [`vp\u002Fcifar10_ddpmpp`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F14AhlnhRryO7XqjrHEtHZRcb_v_bEUd7X?usp=sharing) | 2.78 | 9.64 | - | - |\n| [`vp\u002Fcifar10_ddpmpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1ikbUY_K4Rc2-lPz7baPxdEXtx76Xn5Ov?usp=sharing) | 2.55 | 9.58 | 3.93 | 3.16 |\n| [`vp\u002Fcifar10_ddpmpp_deep_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1F74y6G_AGqPw8DG5uhdO_Kf9DCX1jKfL?usp=sharing) | 2.41 | 9.68 | 3.08 | 3.13 |\n| [`subvp\u002Fcifar10_ddpm_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1Qk6SaMq3EFnMH1rr2OdFZU5IzDKYbskh?usp=sharing) | - | - | 3.56 | 3.05 |\n| [`subvp\u002Fcifar10_ddpmpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1tDz-jQ-tD5A_UjB1gxzoofo07W0LC1aO?usp=sharing) | 2.61 | 9.56 | 3.16 | 3.02 |\n| [`subvp\u002Fcifar10_ddpmpp_deep_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1qjKjuZULYu2uN0sP79yTPkOhEvUPhYnU?usp=sharing) | 2.41 | 9.57 | **2.92** | **2.99** |\n\n| 检查点路径 | 样本 |\n|:-----|:------:|\n| [`ve\u002Fbedroom_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1tcvR65amqrD65Hn0EPlZqNPiCZh2rg4M?usp=sharing) | ![bedroom_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_772513bfb9ae.jpeg) |\n| [`ve\u002Fchurch_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1h8JayORNKTo8pCCLMr0ZDJkM7U87dKM5?usp=sharing) | ![church_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_ecc24b3b908b.jpeg) |\n| [`ve\u002Fffhq_1024_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1GwcthBS4Ry54eA_fIg1hOCfThQ6I3u1L?usp=sharing) |![ffhq_1024](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_c4f07a106670.jpeg)|\n| [`ve\u002Fffhq_256_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1-2tUJ3tOU2AruyMYPB33x1aWVOQMSygM?usp=sharing) |![ffhq_256_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_caa2de1b67b1.jpg)|\n| [`ve\u002Fcelebahq_256_ncsnpp_continuous`](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1LK2bGXpZBzJKLCcL_NfUKsr8dxT8XVh5?usp=sharing) |![celebahq_256_samples](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_readme_358ef1dc50a7.jpg)|\n\n\n\n\n## 演示和教程\n| 链接 | 描述|\n|:----:|:-----|\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1dRR_0gNRmfLtPavX2APzUggBuXyjWW55?usp=sharing)  | 加载我们的预训练检查点，体验采样、似然计算和可控合成（JAX + FLAX）|\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F17lTrPLTt_0EDXa4hkbHmbAFQEkpRDZnh?usp=sharing) | 加载我们的预训练检查点，体验采样、似然计算和可控合成（PyTorch）|\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1SeXMpILhkJPjXUaesvzEhc3Ke6Zl_zxJ?usp=sharing)  | JAX + FLAX 中基于分数的生成模型教程 |\n|[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F120kYYBOVa1i0TD85RjlEkFjaWDxSFUx3?usp=sharing)| PyTorch 中基于分数的生成模型教程 |\n\n\n## 小贴士\n* 使用 JAX 代码库时，可以将多个训练步骤一起进行 JIT 编译，以提高训练速度，但会增加内存消耗。这可以通过 `config.training.n_jitted_steps` 来设置。对于 CIFAR-10 数据集，如果您的 GPU\u002FTPU 内存充足，建议使用 `config.training.n_jitted_steps=5`；否则建议使用 `config.training.n_jitted_steps=1`。目前的实现要求 `config.training.log_freq` 能被 `n_jitted_steps` 整除，这样才能正常进行日志记录和检查点保存。\n* `LangevinCorrector` 的 `snr`（信噪比）参数在某种程度上类似于温度参数。较大的 `snr` 通常会产生更平滑的样本，而较小的 `snr` 则会产生更多样但质量较低的样本。典型的 `snr` 值为 `0.05 - 0.2`，需要通过调优找到最佳平衡点。\n* 对于 VE SDE，建议将 `config.model.sigma_max` 设置为训练数据集中任意两个样本之间的最大距离。\n\n## 参考文献\n\n如果您发现该代码对您的研究有帮助，请考虑引用以下文献：\n```bib\n@inproceedings{\n  song2021scorebased,\n  title={基于分数的生成模型：通过随机微分方程},\n  author={杨松、雅沙·索尔-迪克斯坦、迪德里克·P·金格玛、阿比谢克·库马尔、斯特凡诺·埃尔蒙、本·普尔},\n  booktitle={国际表示学习大会},\n  year={2021},\n  url={https:\u002F\u002Fopenreview.net\u002Fforum?id=PxTIG12RRHS}\n}\n```\n\n本工作建立在一些先前的研究基础上，这些研究也可能对您有所启发：\n\n* 杨松和斯特凡诺·埃尔蒙. “通过估计数据分布的梯度进行生成建模.” 《第33届神经信息处理系统年会论文集》. 2019年.\n* 杨松和斯特凡诺·埃尔蒙. “训练基于分数的生成模型的改进方法.” 《第34届神经信息处理系统年会论文集》. 2020年.\n* 霍, 乔纳森、阿贾伊·贾因和皮特·阿贝尔. “去噪扩散概率模型.” 《第34届神经信息处理系统年会论文集》. 2020年.","# Score-SDE 快速上手指南\n\nScore-SDE 是一个基于随机微分方程（SDE）的分数生成模型官方实现，支持图像生成、修复、着色等任务。本指南帮助开发者快速搭建环境并运行基础示例。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Linux (推荐) 或 macOS\n- **GPU**: 推荐使用 NVIDIA GPU (需安装 CUDA)，JAX 版本对显存要求较高，PyTorch 版本相对节省显存。\n- **Python**: 3.7 或更高版本\n\n### 前置依赖\n本项目主要依赖 `JAX`\u002F`Flax` (官方首选) 或 `PyTorch`。\n- **JAX 版**: 性能更优，但显存占用较大。\n- **PyTorch 版**: 显存占用较小，运行速度稍慢，不支持部分基于预训练分类器的类别条件生成功能。\n\n> **注意**：国内用户建议在安装 Python 包时使用清华或阿里镜像源加速下载。\n\n## 安装步骤\n\n### 1. 克隆代码库\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde.git\ncd score_sde\n```\n\n### 2. 安装依赖包\n使用 pip 安装所需依赖（推荐配置国内镜像源）：\n```bash\npip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n*注：若需使用 PyTorch 版本，请前往 [score_sde_pytorch](https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde_pytorch) 仓库按照其说明安装。*\n\n### 3. 下载评估统计文件 (可选)\n若需进行定量评估（如计算 FID、Inception Score），需下载 CIFAR-10 的统计文件：\n```bash\n# 创建目录\nmkdir -p assets\u002Fstats\n\n# 下载 cifar10_stats.npz (需手动从 Google Drive 下载或使用替代链接)\n# 链接: https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1fXgBupLzThTGLLsiYCHRQJixuDsR1bSI\u002Fview?usp=sharing\n# 下载后将其移动到 assets\u002Fstats\u002F 目录下\n```\n\n### 4. 获取预训练模型 (可选)\n如需直接推理而非重新训练，可从 [Google Drive](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1RAG8qpOTURkrqXKwdAR1d6cU9rwoQYnH?usp=sharing) 下载预训练 checkpoints 并放入对应工作目录。\n\n## 基本使用\n\n所有训练和评估操作均通过 `main.py` 脚本执行。\n\n### 1. 训练模型\n选择一个配置文件开始训练。配置文件位于 `configs\u002F` 目录，命名规则为 `{数据集}_{模型}_{是否连续时间}.py`。\n\n以下示例使用 CIFAR-10 数据集和 NCSN++ 连续时间模型进行训练：\n```bash\npython main.py --config=configs\u002Fcifar10_ncsnpp_continuous.py --workdir=.\u002Fexperiments\u002Fcifar10_test --mode=train\n```\n- `--config`: 指定配置文件路径。\n- `--workdir`: 指定实验输出目录（保存检查点、样本等）。\n- `--mode=train`: 启动训练模式。若目录下存在断点，将自动恢复训练。\n\n### 2. 评估与采样\n训练完成后（或使用预训练模型），可切换至评估模式生成样本并计算指标。\n\n以下示例生成样本并计算 FID 和 Inception Score：\n```bash\npython main.py --config=configs\u002Fcifar10_ncsnpp_continuous.py --workdir=.\u002Fexperiments\u002Fcifar10_test --mode=eval --eval_folder=eval_results --config.eval.enable_sampling=True\n```\n\n若需计算对数似然值 (Log-likelihood \u002F bits\u002Fdim)：\n```bash\npython main.py --config=configs\u002Fcifar10_ncsnpp_continuous.py --workdir=.\u002Fexperiments\u002Fcifar10_test --mode=eval --eval_folder=eval_results --config.eval.enable_bpd=True --config.eval.dataset=test\n```\n\n### 3. 关键参数说明\n通过命令行覆盖配置文件参数（基于 `ml_collections`）：\n- `--config.eval.enable_sampling`: 启用图像采样。\n- `--config.eval.enable_bpd`: 启用 bits\u002Fdim 计算。\n- `--config.eval.dataset`: 指定评估数据集 (`train` 或 `test`)。\n- `--eval_folder`: 评估结果保存的子文件夹名称。\n\n### 快速体验 (Colab)\n如果本地环境配置困难，推荐使用官方提供的 Colab 教程直接运行：\n- **JAX 版本**: [Open in Colab (JAX)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1dRR_0gNRmfLtPavX2APzUggBuXyjWW55?usp=sharing)\n- **PyTorch 版本**: [Open in Colab (PyTorch)](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F17lTrPLTt_0EDXa4hkbHmbAFQEkpRDZnh?usp=sharing)","某医疗影像实验室的研究团队正致力于开发一套系统，旨在将低分辨率、模糊的早期肺部 CT 扫描图重建为高保真图像，以辅助医生更精准地识别微小病灶。\n\n### 没有 score_sde 时\n- **生成质量受限**：传统生成模型在处理复杂医学纹理时容易产生模糊或伪影，难以还原真实的组织细节，导致 FID（弗雷歇初始距离）指标较高，图像可信度低。\n- **修复功能缺失**：面对扫描中常见的遮挡或缺损区域，现有工具缺乏灵活的“图像修复（Inpainting）”能力，无法基于周围健康组织智能补全缺失数据。\n- **理论框架割裂**：团队需分别调试 NCSN 和 DDPM 等不同算法的代码库，缺乏统一的随机微分方程（SDE）视角来优化采样过程，研发效率低下且难以复现前沿成果。\n- **似然评估困难**：无法精确计算生成图像的似然值，导致难以量化模型对数据分布的学习程度，调优过程主要依赖主观视觉判断。\n\n### 使用 score_sde 后\n- **高保真重建**：利用 score_sde 在 CIFAR-10 上达到 FID 2.20 的顶尖生成能力，团队成功合成了纹理清晰、无伪影的高分辨率肺部影像，显著提升了病灶的可辨识度。\n- **灵活条件生成**：借助其强大的条件生成机制，研究人员轻松实现了针对缺损区域的图像修复，模型能依据上下文逻辑自动填补扫描盲区，保持了器官结构的连续性。\n- **统一高效开发**：score_sde 将多种主流分数模型整合于同一模块化框架下，团队得以快速切换并测试不同的 SDE 求解器，大幅缩短了从理论验证到模型部署的周期。\n- **精确量化评估**：通过内置的精确似然计算功能，团队获得了具体的 bits\u002Fdim 数值，能够科学地监控训练收敛情况，确保模型真正掌握了医学影像的深层分布规律。\n\nscore_sde 通过统一的随机微分方程框架，不仅突破了医学影像生成的画质瓶颈，更为复杂的临床图像修复任务提供了可量化、高可靠的解决方案。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fyang-song_score_sde_5c2b74e6.jpg","yang-song","Yang Song","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fyang-song_cc0a3772.jpg","Research Scientist at OpenAI.","OpenAI","Palo Alto, CA",null,"https:\u002F\u002Fyang-song.net","https:\u002F\u002Fgithub.com\u002Fyang-song",[85,89],{"name":86,"color":87,"percentage":88},"Jupyter Notebook","#DA5B0B",94.4,{"name":90,"color":91,"percentage":92},"Python","#3572A5",5.6,1813,229,"2026-04-01T15:02:43","Apache-2.0","未说明","需要 NVIDIA GPU。基准测试使用 4x Nvidia Tesla V100 (32GB)。JAX 版本显存需求较高（单模型训练可达 30GB-75GB），PyTorch 版本相对节省显存（约 20GB）。CUDA 版本未明确说明，但需匹配安装的 JAX 或 PyTorch 版本。",{"notes":100,"python":97,"dependencies":101},"该项目主要基于 JAX\u002FFLAX 开发，同时也提供了 PyTorch 版本的实现链接。JAX 版本训练速度更快但显存占用极高（可通过调整 n_jitted_steps 权衡速度与显存）；PyTorch 版本显存占用较低但运行较慢。部分预训练模型（如 CelebA 原始数据训练的模型）因政策原因未公开，作者提供了在 FFHQ 等数据集上重新训练的替代模型。定量评估需预先下载特定的统计文件（stats files）。",[102,103,104,105,106,107,108,109],"jax","flax","torch","ml_collections","tensorflow","tensorflow-gan","scipy","numpy",[13,14],[112,113,114,115,116,117,102,103,118,119],"score-matching","stochastic-differential-equations","generative-models","score-based-generative-modeling","controllable-generation","inverse-problems","iclr-2021","diffusion-models","2026-03-27T02:49:30.150509","2026-04-06T07:15:10.103787",[123,128,133,138,143,148],{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},12983,"如何在自定义数据集上训练 NCSNPP 模型？特别是如何确定 sigma_max 参数？","对于自定义数据集，可以通过循环迷你批次（mini-batch）来获得合理的近似值。关于 sigma_max 的计算，通常取所有图像对之间距离的最大值（maximum of all pairwise distances），而不是中位数。虽然也可以使用一个过大的 sigma_1，但这会导致采样变慢，并在训练过程中浪费计算资源去处理噪声极大的图像。可以参考相关实现（如 AdversarialConsistentScoreMatching 中的 --compute_approximate_sigma_max 选项）来指导代码实现。","https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fissues\u002F2",{"id":129,"question_zh":130,"answer_zh":131,"source_url":132},12984,"训练参数 n_jitted_steps 的作用是什么？它会影响模型的生成质量或似然估计吗？","n_jitted_steps 参数用于将多个训练步骤一起进行 JIT（即时编译），以便在 GPU\u002FTPU 上更高效地执行，从而加快训练速度。该参数不会影响样本质量或似然估计结果。无论设置为多少，实际运行的训练过程是完全相同的，只是编译和执行的方式不同。","https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fissues\u002F8",{"id":134,"question_zh":135,"answer_zh":136,"source_url":137},12985,"论文中的 Table 3 和 Table 2 结果分别对应哪个预训练检查点（checkpoint）？","根据作者回复，`checkpoint_8` 对应论文中 Table 3 的结果，而另一个检查点对应 Table 2 的结果。","https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fissues\u002F11",{"id":139,"question_zh":140,"answer_zh":141,"source_url":142},12986,"在计算精确似然（exact likelihood）时，为什么代码没有像公式定义那样给输入图像添加均匀噪声（uniform noise）？","这是一个常见的理论实现疑问。在代码实现中，先验对数概率（prior_logp）是基于 ODE 求解器的最终输出（即去噪后的图像）计算得出的，将其输入到高斯分布中。虽然理论公式包含积分项和噪声项，但在具体的数值实现中（如 `likelihood.py`），通过拼接初始数据和零向量，利用 ODE 求解器同时计算潜变量和积分形式，最终得到的结果符合似然计算要求。如果直接对原始含噪图像计算可能会导致负比特每维度（bpd）等异常现象。","https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fissues\u002F24",{"id":144,"question_zh":145,"answer_zh":146,"source_url":147},12987,"在证明 DDPM 是 VP-SDE 的离散化时，公式 (24) 中的近似等式为何成立？","公式 (24) 利用了近似条件 $\\sqrt{1-x} \\approx 1-x\u002F2$（当 $x \\ll 1$ 时）。虽然看起来 $\\beta(t)$ 可能很大，但需要注意时间步长 $\\Delta t = 1\u002FN$。由于论文中假设单步噪声调度系数 $\\beta_i \\ll 1$，因此乘积项 $\\beta(t+\\Delta t)\\Delta t$ 实际上是非常小的，满足近似条件，所以该近似等式成立。","https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fissues\u002F17",{"id":149,"question_zh":150,"answer_zh":151,"source_url":152},12988,"遇到 'TypeError: can't multiply sequence by non-int of type BatchTracer' 错误或相关警告怎么办？","如果遇到此类与 JAX trace 相关的错误或警告，首先尝试增加训练迭代次数（`--config.training.n_iters`）。有用户反馈在单次迭代时会出现警告，但当迭代次数足够大（覆盖一个 epoch）时，警告会消失。此外，确保使用的 JAX、Flax 和 jaxlib 版本与项目要求一致。如果是关于数据集缓存的警告（iterator did not fully read），建议调整数据加载管道顺序，使用 `dataset.take(k).cache().repeat()` 代替 `dataset.cache().take(k).repeat()`。","https:\u002F\u002Fgithub.com\u002Fyang-song\u002Fscore_sde\u002Fissues\u002F1",[]]