[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-kumar-shridhar--PyTorch-BayesianCNN":3,"tool-kumar-shridhar--PyTorch-BayesianCNN":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":70,"readme_en":71,"readme_zh":72,"quickstart_zh":73,"use_case_zh":74,"hero_image_url":75,"owner_login":76,"owner_name":77,"owner_avatar_url":78,"owner_bio":79,"owner_company":80,"owner_location":81,"owner_email":82,"owner_twitter":83,"owner_website":84,"owner_url":85,"languages":86,"stars":91,"forks":92,"last_commit_at":93,"license":94,"difficulty_score":23,"env_os":95,"env_gpu":96,"env_ram":96,"env_deps":97,"category_tags":102,"github_topics":103,"view_count":10,"oss_zip_url":121,"oss_zip_packed_at":121,"status":16,"created_at":122,"updated_at":123,"faqs":124,"releases":165},435,"kumar-shridhar\u002FPyTorch-BayesianCNN","PyTorch-BayesianCNN","Bayesian Convolutional Neural Network with Variational Inference based on Bayes by Backprop in PyTorch. ","PyTorch-BayesianCNN 是一个基于 PyTorch 实现的贝叶斯卷积神经网络（Bayesian CNN）开源项目，采用“Bayes by Backprop”方法进行变分推断，用于近似神经网络权重的后验分布。与传统 CNN 输出单一确定性预测不同，它能提供预测的不确定性估计，在数据有限或对可靠性要求高的场景（如医疗、自动驾驶）中更具优势。\n\n该项目主要面向机器学习研究人员和开发者，尤其适合希望在深度学习模型中引入贝叶斯推理、探索不确定性量化或复现相关论文实验的人群。普通用户或设计师通常无需直接使用。\n\n其技术亮点包括两种贝叶斯层实现：标准 BBB（Bayes by Backprop）和结合局部重参数化技巧（LRT）的 BBB_LRT，后者可提升训练效率。用户只需继承 ModuleWrapper 并替换常规卷积\u002F全连接层为 BBBConv2d 和 BBBLinear，即可快速构建全贝叶斯网络，且无需手动编写 forward 方法。模型输出包含 logits 和 KL 散度，便于集成到标准训练流程中。项目已在 MNIST、CIFAR10 等数据集上验证，性能与传统 CNN 相","PyTorch-BayesianCNN 是一个基于 PyTorch 实现的贝叶斯卷积神经网络（Bayesian CNN）开源项目，采用“Bayes by Backprop”方法进行变分推断，用于近似神经网络权重的后验分布。与传统 CNN 输出单一确定性预测不同，它能提供预测的不确定性估计，在数据有限或对可靠性要求高的场景（如医疗、自动驾驶）中更具优势。\n\n该项目主要面向机器学习研究人员和开发者，尤其适合希望在深度学习模型中引入贝叶斯推理、探索不确定性量化或复现相关论文实验的人群。普通用户或设计师通常无需直接使用。\n\n其技术亮点包括两种贝叶斯层实现：标准 BBB（Bayes by Backprop）和结合局部重参数化技巧（LRT）的 BBB_LRT，后者可提升训练效率。用户只需继承 ModuleWrapper 并替换常规卷积\u002F全连接层为 BBBConv2d 和 BBBLinear，即可快速构建全贝叶斯网络，且无需手动编写 forward 方法。模型输出包含 logits 和 KL 散度，便于集成到标准训练流程中。项目已在 MNIST、CIFAR10 等数据集上验证，性能与传统 CNN 相当，同时提供额外的不确定性信息。","\n[![Python 3.7+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython-3.7+-blue.svg)](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002Frelease\u002Fpython-376\u002F)\n[![Pytorch 1.3](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpytorch-1.3.1-blue.svg)](https:\u002F\u002Fpytorch.org\u002F)\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-yellow.svg)](https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fblob\u002Fmaster\u002FLICENSE)\n[![arxiv](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fstat.ML-arXiv%3A2002.02797-B31B1B.svg)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1901.02731)\n\nWe introduce **Bayesian convolutional neural networks with variational inference**, a variant of convolutional neural networks (CNNs), in which the intractable posterior probability distributions over weights are inferred by **Bayes by Backprop**. We demonstrate how our proposed variational inference method achieves performances equivalent to frequentist inference in identical architectures on several datasets (MNIST, CIFAR10, CIFAR100) as described in the [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1901.02731).\n\n---------------------------------------------------------------------------------------------------------\n\n\n### Filter weight distributions in a Bayesian Vs Frequentist approach\n\n![Distribution over weights in a CNN's filter.](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkumar-shridhar_PyTorch-BayesianCNN_readme_847f55d93dea.png)\n\n---------------------------------------------------------------------------------------------------------\n\n### Fully Bayesian perspective of an entire CNN\n\n![Distributions must be over weights in convolutional layers and weights in fully-connected layers.](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkumar-shridhar_PyTorch-BayesianCNN_readme_aeeb7060ce5e.png)\n\n---------------------------------------------------------------------------------------------------------\n\n\n\n### Layer types\n\nThis repository contains two types of bayesian lauer implementation:  \n* **BBB (Bayes by Backprop):**  \n  Based on [this paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1505.05424). This layer samples all the weights individually and then combines them with the inputs to compute a sample from the activations.\n\n* **BBB_LRT (Bayes by Backprop w\u002F Local Reparametrization Trick):**  \n  This layer combines Bayes by Backprop with local reparametrization trick from [this paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1506.02557). This trick makes it possible to directly sample from the distribution over activations.\n---------------------------------------------------------------------------------------------------------\n\n\n\n### Make your custom Bayesian Network?\nTo make a custom Bayesian Network, inherit `layers.misc.ModuleWrapper` instead of `torch.nn.Module` and use `BBBLinear` and `BBBConv2d` from any of the given layers (`BBB` or `BBB_LRT`) instead of `torch.nn.Linear` and `torch.nn.Conv2d`. Moreover, no need to define `forward` method. It'll automatically be taken care of by `ModuleWrapper`. \n\nFor example:  \n```python\nclass Net(nn.Module):\n\n  def __init__(self):\n    super().__init__()\n    self.conv = nn.Conv2d(3, 16, 5, strides=2)\n    self.bn = nn.BatchNorm2d(16)\n    self.relu = nn.ReLU()\n    self.fc = nn.Linear(800, 10)\n\n  def forward(self, x):\n    x = self.conv(x)\n    x = self.bn(x)\n    x = self.relu(x)\n    x = x.view(-1, 800)\n    x = self.fc(x)\n    return x\n```\nAbove Network can be converted to Bayesian as follows:\n```python\nclass Net(ModuleWrapper):\n\n  def __init__(self):\n    super().__init__()\n    self.conv = BBBConv2d(3, 16, 5, strides=2)\n    self.bn = nn.BatchNorm2d(16)\n    self.relu = nn.ReLU()\n    self.flatten = FlattenLayer(800)\n    self.fc = BBBLinear(800, 10)\n```\n\n#### Notes:\n1. Add `FlattenLayer` before first `BBBLinear` block.  \n2. `forward` method of the model will return a tuple as `(logits, kl)`.\n3. `priors` can be passed as an argument to the layers. Default value is:  \n```python\npriors={\n    'prior_mu': 0,\n    'prior_sigma': 0.1,\n    'posterior_mu_initial': (0, 0.1),  # (mean, std) normal_\n    'posterior_rho_initial': (-3, 0.1),  # (mean, std) normal_\n}\n```\n\n---------------------------------------------------------------------------------------------------------\n\n### How to perform standard experiments?\nCurrently, following datasets and models are supported.  \n* Datasets: MNIST, CIFAR10, CIFAR100  \n* Models: AlexNet, LeNet, 3Conv3FC  \n\n#### Bayesian\n\n`python main_bayesian.py`\n* set hyperparameters in `config_bayesian.py`\n\n\n#### Frequentist\n\n`python main_frequentist.py`\n* set hyperparameters in `config_frequentist.py`\n\n---------------------------------------------------------------------------------------------------------\n\n\n\n### Directory Structure:\n`layers\u002F`:  Contains `ModuleWrapper`, `FlattenLayer`, `BBBLinear` and `BBBConv2d`.  \n`models\u002FBayesianModels\u002F`: Contains standard Bayesian models (BBBLeNet, BBBAlexNet, BBB3Conv3FC).  \n`models\u002FNonBayesianModels\u002F`: Contains standard Non-Bayesian models (LeNet, AlexNet).  \n`checkpoints\u002F`: Checkpoint directory: Models will be saved here.  \n`tests\u002F`: Basic unittest cases for layers and models.  \n`main_bayesian.py`: Train and Evaluate Bayesian models.  \n`config_bayesian.py`: Hyperparameters for `main_bayesian` file.  \n`main_frequentist.py`: Train and Evaluate non-Bayesian (Frequentist) models.  \n`config_frequentist.py`: Hyperparameters for `main_frequentist` file.  \n\n---------------------------------------------------------------------------------------------------------\n\n\n\n### Uncertainty Estimation:  \nThere are two types of uncertainties: **Aleatoric** and **Epistemic**.  \nAleatoric uncertainty is a measure for the variation of data and Epistemic uncertainty is caused by the model.  \nHere, two methods are provided in `uncertainty_estimation.py`, those are `'softmax'` & `'normalized'` and are respectively based on equation 4 from [this paper](https:\u002F\u002Fopenreview.net\u002Fpdf?id=Sk_P2Q9sG) and equation 15 from [this paper](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1806.05978.pdf).  \nAlso, `uncertainty_estimation.py` can be used to compare uncertainties by a Bayesian Neural Network on `MNIST` and `notMNIST` dataset. You can provide arguments like:     \n1. `net_type`: `lenet`, `alexnet` or `3conv3fc`. Default is `lenet`.   \n2. `weights_path`: Weights for the given `net_type`. Default is `'checkpoints\u002FMNIST\u002Fbayesian\u002Fmodel_lenet.pt'`.  \n3. `not_mnist_dir`: Directory of `notMNIST` dataset. Default is `'data\\'`. \n4. `num_batches`: Number of batches for which uncertainties need to be calculated.  \n\n**Notes**:  \n1. You need to download the [notMNIST](http:\u002F\u002Fyaroslavvb.blogspot.com\u002F2011\u002F09\u002Fnotmnist-dataset.html) dataset from [here](http:\u002F\u002Fyaroslavvb.com\u002Fupload\u002FnotMNIST\u002FnotMNIST_small.tar.gz).  \n2. Parameters `layer_type` and `activation_type` used in `uncertainty_etimation.py` needs to be set from `config_bayesian.py` in order to match with provided weights. \n\n---------------------------------------------------------------------------------------------------------\n\n\n\nIf you are using this work, please cite:\n\n```\n@article{shridhar2019comprehensive,\n  title={A comprehensive guide to bayesian convolutional neural network with variational inference},\n  author={Shridhar, Kumar and Laumann, Felix and Liwicki, Marcus},\n  journal={arXiv preprint arXiv:1901.02731},\n  year={2019}\n}\n```\n\n```\n@article{shridhar2018uncertainty,\n  title={Uncertainty estimations by softplus normalization in bayesian convolutional neural networks with variational inference},\n  author={Shridhar, Kumar and Laumann, Felix and Liwicki, Marcus},\n  journal={arXiv preprint arXiv:1806.05978},\n  year={2018}\n}\n}\n```\n\n--------------------------------------------------------------------------------------------------------\n","[![Python 3.7+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython-3.7+-blue.svg)](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002Frelease\u002Fpython-376\u002F)\n[![Pytorch 1.3](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpytorch-1.3.1-blue.svg)](https:\u002F\u002Fpytorch.org\u002F)\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-yellow.svg)](https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fblob\u002Fmaster\u002FLICENSE)\n[![arxiv](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fstat.ML-arXiv%3A2002.02797-B31B1B.svg)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1901.02731)\n\n我们提出了**基于变分推断（variational inference）的贝叶斯卷积神经网络（Bayesian convolutional neural networks）**，这是卷积神经网络（CNNs）的一种变体，其中权重上难以处理的后验概率分布通过 **Bayes by Backprop** 方法进行推断。我们在多个数据集（MNIST、CIFAR10、CIFAR100）上展示了所提出的变分推断方法在相同网络架构下能达到与频率学派推断（frequentist inference）相当的性能，具体细节见[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1901.02731)。\n\n---------------------------------------------------------------------------------------------------------\n\n\n### 贝叶斯方法与频率学派方法中的卷积核权重分布\n\n![Distribution over weights in a CNN's filter.](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkumar-shridhar_PyTorch-BayesianCNN_readme_847f55d93dea.png)\n\n---------------------------------------------------------------------------------------------------------\n\n### 整个 CNN 的全贝叶斯视角\n\n![Distributions must be over weights in convolutional layers and weights in fully-connected layers.](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkumar-shridhar_PyTorch-BayesianCNN_readme_aeeb7060ce5e.png)\n\n---------------------------------------------------------------------------------------------------------\n\n\n\n### 层类型\n\n本仓库包含两种贝叶斯层（bayesian layer）的实现：  \n* **BBB (Bayes by Backprop):**  \n  基于[这篇论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1505.05424)。该层对所有权重分别采样，然后将其与输入结合以计算激活值的一个样本。\n\n* **BBB_LRT (Bayes by Backprop w\u002F Local Reparametrization Trick):**  \n  该层将 Bayes by Backprop 与[这篇论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1506.02557)中提出的局部重参数化技巧（Local Reparametrization Trick）相结合。该技巧使得可以直接从激活值的分布中采样。\n---------------------------------------------------------------------------------------------------------\n\n\n\n### 如何构建自定义贝叶斯网络？\n\n要构建自定义贝叶斯网络，请继承 `layers.misc.ModuleWrapper` 而非 `torch.nn.Module`，并使用任一实现（`BBB` 或 `BBB_LRT`）中的 `BBBLinear` 和 `BBBConv2d` 替代 `torch.nn.Linear` 和 `torch.nn.Conv2d`。此外，无需定义 `forward` 方法，`ModuleWrapper` 会自动处理。\n\n例如：  \n```python\nclass Net(nn.Module):\n\n  def __init__(self):\n    super().__init__()\n    self.conv = nn.Conv2d(3, 16, 5, strides=2)\n    self.bn = nn.BatchNorm2d(16)\n    self.relu = nn.ReLU()\n    self.fc = nn.Linear(800, 10)\n\n  def forward(self, x):\n    x = self.conv(x)\n    x = self.bn(x)\n    x = self.relu(x)\n    x = x.view(-1, 800)\n    x = self.fc(x)\n    return x\n```\n上述网络可转换为贝叶斯版本如下：\n```python\nclass Net(ModuleWrapper):\n\n  def __init__(self):\n    super().__init__()\n    self.conv = BBBConv2d(3, 16, 5, strides=2)\n    self.bn = nn.BatchNorm2d(16)\n    self.relu = nn.ReLU()\n    self.flatten = FlattenLayer(800)\n    self.fc = BBBLinear(800, 10)\n```\n\n#### 注意事项：\n1. 在第一个 `BBBLinear` 模块前添加 `FlattenLayer`。  \n2. 模型的 `forward` 方法将返回一个元组 `(logits, kl)`。\n3. 可以将 `priors` 作为参数传入各层。默认值为：  \n```python\npriors={\n    'prior_mu': 0,\n    'prior_sigma': 0.1,\n    'posterior_mu_initial': (0, 0.1),  # (均值, 标准差) normal_\n    'posterior_rho_initial': (-3, 0.1),  # (均值, 标准差) normal_\n}\n```\n\n---------------------------------------------------------------------------------------------------------\n\n### 如何进行标准实验？\n\n目前支持以下数据集和模型。  \n* 数据集：MNIST、CIFAR10、CIFAR100  \n* 模型：AlexNet、LeNet、3Conv3FC  \n\n#### 贝叶斯方法\n\n`python main_bayesian.py`\n* 在 `config_bayesian.py` 中设置超参数\n\n\n#### 频率学派方法\n\n`python main_frequentist.py`\n* 在 `config_frequentist.py` 中设置超参数\n\n---------------------------------------------------------------------------------------------------------\n\n\n\n### 目录结构：\n`layers\u002F`: 包含 `ModuleWrapper`、`FlattenLayer`、`BBBLinear` 和 `BBBConv2d`。  \n`models\u002FBayesianModels\u002F`: 包含标准贝叶斯模型（BBBLeNet、BBBAlexNet、BBB3Conv3FC）。  \n`models\u002FNonBayesianModels\u002F`: 包含标准非贝叶斯模型（LeNet、AlexNet）。  \n`checkpoints\u002F`: 检查点目录：模型将保存在此处。  \n`tests\u002F`: 层和模型的基本单元测试用例。  \n`main_bayesian.py`: 训练和评估贝叶斯模型。  \n`config_bayesian.py`: `main_bayesian.py` 的超参数配置。  \n`main_frequentist.py`: 训练和评估非贝叶斯（频率学派）模型。  \n`config_frequentist.py`: `main_frequentist.py` 的超参数配置。  \n\n---------------------------------------------------------------------------------------------------------\n\n### 不确定性估计（Uncertainty Estimation）:  \n存在两种类型的不确定性：**Aleatoric（偶然不确定性）** 和 **Epistemic（认知不确定性）**。  \nAleatoric 不确定性用于衡量数据本身的变异性，而 Epistemic 不确定性则源于模型本身。  \n在 `uncertainty_estimation.py` 中提供了两种方法：`'softmax'` 与 `'normalized'`，分别基于 [这篇论文](https:\u002F\u002Fopenreview.net\u002Fpdf?id=Sk_P2Q9sG) 的公式 4 和 [这篇论文](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1806.05978.pdf) 的公式 15。  \n此外，`uncertainty_estimation.py` 还可用于在 `MNIST` 和 `notMNIST` 数据集上，通过贝叶斯神经网络（Bayesian Neural Network）比较不确定性。你可以提供以下参数：     \n1. `net_type`: `lenet`、`alexnet` 或 `3conv3fc`。默认为 `lenet`。   \n2. `weights_path`: 对应 `net_type` 的权重文件路径。默认为 `'checkpoints\u002FMNIST\u002Fbayesian\u002Fmodel_lenet.pt'`。  \n3. `not_mnist_dir`: `notMNIST` 数据集的目录。默认为 `'data\\'`。 \n4. `num_batches`: 需要计算不确定性的批次数。  \n\n**注意事项**:  \n1. 你需要从 [此处](http:\u002F\u002Fyaroslavvb.com\u002Fupload\u002FnotMNIST\u002FnotMNIST_small.tar.gz) 下载 [notMNIST](http:\u002F\u002Fyaroslavvb.blogspot.com\u002F2011\u002F09\u002Fnotmnist-dataset.html) 数据集。  \n2. 在 `uncertainty_estimation.py` 中使用的参数 `layer_type` 和 `activation_type` 需要根据 `config_bayesian.py` 进行设置，以确保与提供的权重匹配。 \n\n---------------------------------------------------------------------------------------------------------\n\n\n\n如果你使用了本项目的工作，请引用以下文献：\n\n```\n@article{shridhar2019comprehensive,\n  title={A comprehensive guide to bayesian convolutional neural network with variational inference},\n  author={Shridhar, Kumar and Laumann, Felix and Liwicki, Marcus},\n  journal={arXiv preprint arXiv:1901.02731},\n  year={2019}\n}\n```\n\n```\n@article{shridhar2018uncertainty,\n  title={Uncertainty estimations by softplus normalization in bayesian convolutional neural networks with variational inference},\n  author={Shridhar, Kumar and Laumann, Felix and Liwicki, Marcus},\n  journal={arXiv preprint arXiv:1806.05978},\n  year={2018}\n}\n```","# PyTorch-BayesianCNN 快速上手指南\n\n## 环境准备\n\n- **Python 版本**：3.7 或更高\n- **PyTorch 版本**：1.3.1\n- **操作系统**：Linux \u002F macOS \u002F Windows 均可\n\n建议使用国内镜像源加速依赖安装（如清华源、阿里源）。\n\n## 安装步骤\n\n1. 克隆仓库：\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN.git\ncd PyTorch-BayesianCNN\n```\n\n2. 安装依赖（推荐使用虚拟环境）：\n```bash\npip install torch==1.3.1 torchvision\n# 如需加速，可使用清华源：\n# pip install torch==1.3.1 torchvision -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n> 注意：该工具不依赖额外的第三方库，仅需 PyTorch 和标准库。\n\n## 基本使用\n\n### 1. 构建自定义贝叶斯网络\n\n继承 `layers.misc.ModuleWrapper`，并使用 `BBBConv2d` 和 `BBBLinear` 替代标准层：\n\n```python\nfrom layers.misc import ModuleWrapper, FlattenLayer\nfrom layers.BBB import BBBConv2d, BBBLinear\n\nclass Net(ModuleWrapper):\n    def __init__(self):\n        super().__init__()\n        self.conv = BBBConv2d(3, 16, 5, stride=2)\n        self.bn = nn.BatchNorm2d(16)\n        self.relu = nn.ReLU()\n        self.flatten = FlattenLayer(800)\n        self.fc = BBBLinear(800, 10)\n```\n\n> 注意：\n> - 在首个 `BBBLinear` 前添加 `FlattenLayer`\n> - 模型 `forward` 返回 `(logits, kl)` 元组\n> - 可通过 `priors` 参数自定义先验分布（默认值见 README）\n\n### 2. 训练标准贝叶斯模型\n\n支持数据集：MNIST、CIFAR10、CIFAR100  \n支持模型：LeNet、AlexNet、3Conv3FC\n\n修改配置文件后运行：\n\n```bash\n# 贝叶斯训练\npython main_bayesian.py\n\n# 频率学派对比实验\npython main_frequentist.py\n```\n\n配置文件位于：\n- `config_bayesian.py`\n- `config_frequentist.py`\n\n### 3. 不确定性评估（可选）\n\n使用预训练权重评估模型不确定性：\n\n```bash\npython uncertainty_estimation.py \\\n  --net_type lenet \\\n  --weights_path checkpoints\u002FMNIST\u002Fbayesian\u002Fmodel_lenet.pt \\\n  --not_mnist_dir data\u002F\n```\n\n> 需提前下载 [notMNIST 数据集](http:\u002F\u002Fyaroslavvb.com\u002Fupload\u002FnotMNIST\u002FnotMNIST_small.tar.gz) 并解压至 `data\u002F` 目录。","某医疗AI初创公司正在开发一个用于皮肤癌图像分类的移动端应用，需在有限数据下训练轻量级CNN模型，并评估预测结果的可信度以辅助医生决策。\n\n### 没有 PyTorch-BayesianCNN 时\n- 使用标准PyTorch CNN训练后，模型对模糊或罕见皮损图像仍会输出高置信度预测，无法区分“确定正常”和“不确定但猜是正常”。\n- 为估计不确定性，团队尝试集成多个模型（MC Dropout + 多次训练），但推理延迟翻倍，难以部署到手机端。\n- 超参数调优依赖大量验证数据，而医疗数据标注成本高、样本仅千余张，容易过拟合且泛化能力差。\n- 无法直接获取权重的分布信息，难以分析模型在哪些特征上存在高不确定性，影响临床信任度。\n\n### 使用 PyTorch-BayesianCNN 后\n- 通过内置的变分推断机制，单次前向传播即可输出预测 logits 和 KL 散度，结合多次采样轻松量化预测不确定性，识别出低质量输入。\n- 利用 BBB_LRT 层实现高效不确定性估计，推理速度接近普通CNN，满足移动端实时性要求。\n- 贝叶斯先验自然引入正则化，在小样本下显著降低过拟合，CIFAR10风格的皮肤病变分类准确率提升约4%。\n- 可视化卷积核权重分布，帮助算法团队与皮肤科医生共同理解模型关注区域是否合理，增强可解释性。\n\nPyTorch-BayesianCNN 让小样本医疗图像任务在保持轻量的同时获得可靠的不确定性估计，弥合了AI预测与临床决策之间的信任鸿沟。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkumar-shridhar_PyTorch-BayesianCNN_9c089d6a.png","kumar-shridhar","Kumar Shridhar","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fkumar-shridhar_ca968bc5.jpg","PhD @ ETH Zürich in NLP and ML","ETH Zürich","Zürich, Switzerland","shridhar.stark@gmail.com","JupyterAI","https:\u002F\u002Fkumar-shridhar.github.io\u002F","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar",[87],{"name":88,"color":89,"percentage":90},"Python","#3572A5",100,1570,335,"2026-04-03T02:22:20","MIT","Linux, macOS, Windows","未说明",{"notes":98,"python":99,"dependencies":100},"项目支持 MNIST、CIFAR10 和 CIFAR100 数据集；若需进行不确定性评估，需额外下载 notMNIST 数据集。模型训练和评估分别通过 main_bayesian.py 和 main_frequentist.py 脚本进行，并需在对应的 config 文件中设置超参数。","3.7+",[101],"torch==1.3.1",[14,13],[104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120],"convolutional-neural-networks","bayesian-network","bayesian-convnets","bayes-by-backprop","pytorch","python","pytorch-cnn","bayesian-neural-networks","bayesian-deep-learning","bayesian-inference","bayesian-statistics","image-recognition","aleatoric-uncertainties","bayes","bayesian-networks","variational-inference","variational-bayes",null,"2026-03-27T02:49:30.150509","2026-04-06T06:44:05.406344",[125,130,135,140,145,150,155,160],{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},1659,"训练时损失（loss）出现 NaN 是什么原因？如何解决？","NaN 损失通常源于 KL 散度计算中的数值不稳定，特别是在调用 net.probforward(x) 时。维护者已修复该问题，建议使用最新代码。若仍遇到此问题，可检查是否使用了旧版本代码，并确保 KL 散度正确求和为标量而非张量。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F8",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},1660,"BBBConv2d 和 BBBLinearFactorial 中的权重参数是否被正确用于 KL 散度和前向传播？","有用户指出，KL 散度使用的是 conv_qw\u002Ffc_qw，而前向传播使用的是 qw_mean，两者不一致可能导致先验未正确施加于实际使用的权重。维护者回应称尝试统一后网络难以收敛，但鼓励提交 PR 进一步验证。建议确认当前实现中数据似然和 KL 是否基于相同的权重分布参数（均值和方差）。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F7",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},1661,"q_logvar_init 和 p_logvar_init 的初始值是什么？它们会影响模型性能吗？","在 BBBConv2d 中，q_logvar_init 和 p_logvar_init 是可学习或可配置的初始化参数，用于设定变分分布和先验分布的对数方差。虽然代码中未显式指定默认值，但其初始设置会影响训练稳定性与收敛。有用户质疑为何先验分布（如 w_p ~ N(0, 0.05)）是固定的——这是因为贝叶斯神经网络通常假设简单先验（如标准正态），并通过 KL 正则化引导变分后验逼近该先验。初始值不同可能有助于探索，但实践中常设为相近值以稳定训练。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F27",{"id":141,"question_zh":142,"answer_zh":143,"source_url":144},1662,"为什么新版 AlexNet 实现中 CNN 层的 KL 项未包含在总损失中？","这是一个被确认的 bug。早期版本包含所有层的 KL 项，但更新后遗漏了 CNN 层的 KL。维护者已尝试修复，但有用户反馈若简单恢复 kl += _kl 会导致模型无法收敛。建议使用修复后的最新代码，并监控训练是否稳定；若仍存在问题，可手动检查各层是否正确返回并累加 KL 散度。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F25",{"id":146,"question_zh":147,"answer_zh":148,"source_url":149},1663,"运行 Bayesian_CNN_Detailed.ipynb 时出现 KL 张量尺寸不匹配错误怎么办？","错误原因是 KL 散度未被正确归约为标量，而是保留了与卷积核相同的空间维度（如 [6,3,5,5]），导致无法与标量损失相加。解决方案是在 probforward 中对 _kl 调用 .sum() 将其转为标量。但注意：仅求和可能使准确率下降，需结合其他训练调整（如学习率、先验设置）以恢复性能。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F14",{"id":151,"question_zh":152,"answer_zh":153,"source_url":154},1664,"使用贝叶斯 CNN 处理图像时输出带有噪声，如何解决？","输出噪声可能源于采样方法效率低下或贝叶斯层实现中的数值问题。维护者指出这可能与最新的贝叶斯分布层更新有关，并表示将在后续代码更新中修复（当时预计 10 天内）。建议更新至最新版本代码，或暂时回退到能正常工作的旧版本进行验证。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F10",{"id":156,"question_zh":157,"answer_zh":158,"source_url":159},1665,"如何正确计算测试时的不确定性（epistemic 和 aleatoric）？","原代码在 batch 测试时仅取第一个样本的第一个实例的最大概率来计算置信度，导致不确定性估计错误。正确做法应是对每个输入实例的多次采样结果（如 num_samples=10）分别计算预测概率，再基于这些样本统计不确定性（例如：epistemic 不确定性可用预测熵的均值，aleatoric 可用熵的方差）。需修改 main_Bayes.py 第 226 行附近逻辑，确保对每个实例的所有采样结果进行聚合。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F32",{"id":161,"question_zh":162,"answer_zh":163,"source_url":164},1666,"BBBLayers 初始化时出现语法错误，提示非默认参数位于默认参数之后，如何解决？","这是 Python 函数定义的语法问题：在 __init__ 方法中，带有默认值的参数不能出现在无默认值参数之前。例如 (p_logvar_init, q_logvar_init=None) 是非法的。解决方案是调整参数顺序，将所有无默认值参数放在前面。用户可自行修改 BBBLayers 文件中的参数顺序，或将缺失的默认值补全以符合 Python 语法规则。","https:\u002F\u002Fgithub.com\u002Fkumar-shridhar\u002FPyTorch-BayesianCNN\u002Fissues\u002F20",[]]