[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-XifengGuo--CapsNet-Keras":3,"tool-XifengGuo--CapsNet-Keras":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},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,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},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 真正成长为懂上",144730,2,"2026-04-07T23:26:32",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107888,"2026-04-06T11:32:50",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":78,"owner_twitter":78,"owner_website":79,"owner_url":80,"languages":81,"stars":86,"forks":87,"last_commit_at":88,"license":89,"difficulty_score":10,"env_os":90,"env_gpu":91,"env_ram":90,"env_deps":92,"category_tags":99,"github_topics":100,"view_count":32,"oss_zip_url":78,"oss_zip_packed_at":78,"status":17,"created_at":107,"updated_at":108,"faqs":109,"releases":139},5392,"XifengGuo\u002FCapsNet-Keras","CapsNet-Keras","A Keras implementation of CapsNet in NIPS2017 paper \"Dynamic Routing Between Capsules\". Now test error ＝ 0.34%. ","CapsNet-Keras 是经典论文《Dynamic Routing Between Capsules》中胶囊网络（CapsNet）的 Keras 实现版本，旨在为开发者提供复现这一前沿深度学习架构的便捷途径。传统卷积神经网络在处理图像空间层级关系时存在局限，而胶囊网络通过“动态路由”机制，能更有效地捕捉物体姿态与部分 - 整体关系，显著提升识别鲁棒性。该工具在 MNIST 数据集上表现优异，平均测试错误率低至 0.34%，最佳可达 0.30%。\n\n项目不仅完整还原了论文核心算法，还针对实际训练进行了优化调整，例如引入学习率衰减策略、明确重构损失系数计算方式，并提供了单卡及多 GPU 并行训练脚本，大幅降低实验门槛。代码支持 TensorFlow 1.x 与 2.x 双版本，兼顾兼容性与现代开发需求。用户可快速上手训练、评估模型，甚至直接加载预训练权重进行推理验证。\n\n适合人工智能研究人员、深度学习工程师及对新型网络结构感兴趣的高校师生使用。无论是希望深入理解胶囊网络原理，还是想将其应用于小样本或复杂场景分类任务，CapsNet-Keras 都提供了清晰、可运行且结果可复现的参考实现","CapsNet-Keras 是经典论文《Dynamic Routing Between Capsules》中胶囊网络（CapsNet）的 Keras 实现版本，旨在为开发者提供复现这一前沿深度学习架构的便捷途径。传统卷积神经网络在处理图像空间层级关系时存在局限，而胶囊网络通过“动态路由”机制，能更有效地捕捉物体姿态与部分 - 整体关系，显著提升识别鲁棒性。该工具在 MNIST 数据集上表现优异，平均测试错误率低至 0.34%，最佳可达 0.30%。\n\n项目不仅完整还原了论文核心算法，还针对实际训练进行了优化调整，例如引入学习率衰减策略、明确重构损失系数计算方式，并提供了单卡及多 GPU 并行训练脚本，大幅降低实验门槛。代码支持 TensorFlow 1.x 与 2.x 双版本，兼顾兼容性与现代开发需求。用户可快速上手训练、评估模型，甚至直接加载预训练权重进行推理验证。\n\n适合人工智能研究人员、深度学习工程师及对新型网络结构感兴趣的高校师生使用。无论是希望深入理解胶囊网络原理，还是想将其应用于小样本或复杂场景分类任务，CapsNet-Keras 都提供了清晰、可运行且结果可复现的参考实现，是探索下一代视觉模型的理想起点。","# CapsNet-Keras\n[![License](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fmashape\u002Fapistatus.svg?maxAge=2592000)](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Fblob\u002Fmaster\u002FLICENSE)\n\nA Keras (branch [tf2.2](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Ftree\u002Ftf2.2) supports TensorFlow 2) implementation of CapsNet in the paper:   \n[Sara Sabour, Nicholas Frosst, Geoffrey E Hinton. Dynamic Routing Between Capsules. NIPS 2017](https:\u002F\u002Farxiv.org\u002Fabs\u002F1710.09829)   \nThe current `average test error = 0.34%` and `best test error = 0.30%`.   \n \n**Differences with the paper:**   \n- We use the learning rate decay with `decay factor = 0.9` and `step = 1 epoch`,    \nwhile the paper did not give the detailed parameters (or they didn't use it?).\n- We only report the test errors after `50 epochs` training.   \nIn the paper, I suppose they trained for `1250 epochs` according to Figure A.1?\nSounds crazy, maybe I misunderstood.\n- We use MSE (mean squared error) as the reconstruction loss and \nthe coefficient for the loss is `lam_recon=0.0005*784=0.392`.   \nThis should be **equivalent** with using SSE (sum squared error) and `lam_recon=0.0005` as in the paper.\n\n## Warnning\n\nPlease use Keras==2.0.7 with TensorFlow==1.2 backend, or the `K.batch_dot` function may not work correctly.\n\nHowever, if you use **Tensorflow>=2.0**, then checkout branch [tf2.2](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Ftree\u002Ftf2.2)\n\n\n## Usage\n\n**Step 1. Clone this repository to local.**\n```\ngit clone https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras.git capsnet-keras\ncd capsnet-keras\ngit checkout tf2.2 # Only if use Tensorflow>=2.0\n```\n\n**Step 2.\nInstall Keras==2.0.7 with TensorFlow==1.2 backend.**\n```\npip install tensorflow-gpu==1.2\npip install keras==2.0.7\n```\n**or install Tensorflow>=2.0**\n```\npip install tensorflow==2.2\n```\n\n\n\n**Step 3. Train a CapsNet on MNIST**  \n\nTraining with default settings:\n```\npython capsulenet.py\n```\n\nMore detailed usage run for help:\n```\npython capsulenet.py -h\n```\n\n**Step 4. Test a pre-trained CapsNet model**\n\nSuppose you have trained a model using the above command, then the trained model will be\nsaved to `result\u002Ftrained_model.h5`. Now just launch the following command to get test results.\n```\n$ python capsulenet.py -t -w result\u002Ftrained_model.h5\n```\nIt will output the testing accuracy and show the reconstructed images.\nThe testing data is same as the validation data. It will be easy to test on new data, \njust change the code as you want.\n\nYou can also just *download a model I trained* from \nhttps:\u002F\u002Fpan.baidu.com\u002Fs\u002F1sldqQo1\nor\nhttps:\u002F\u002Fdrive.google.com\u002Fopen?id=1A7pRxH7iWzYZekzr-O0nrwqdUUpUpkik\n\n\n**Step 5. Train on multi gpus**   \n\nThis requires `Keras>=2.0.9`. After updating Keras:   \n```\npython capsulenet-multi-gpu.py --gpus 2\n```\nIt will automatically train on multi gpus for 50 epochs and then output the performance on test dataset.\nBut during training, no validation accuracy is reported.\n\n## Results\n\n#### Test Errors   \n\nCapsNet classification test **error** on MNIST. Average and standard deviation results are\nreported by 3 trials. The results can be reproduced by launching the following commands.   \n ```\n python capsulenet.py --routings 1 --lam_recon 0.0    #CapsNet-v1   \n python capsulenet.py --routings 1 --lam_recon 0.392  #CapsNet-v2\n python capsulenet.py --routings 3 --lam_recon 0.0    #CapsNet-v3 \n python capsulenet.py --routings 3 --lam_recon 0.392  #CapsNet-v4\n```\n   Method     |   Routing   |   Reconstruction  |  MNIST (%)  |  *Paper*    \n   :---------|:------:|:---:|:----:|:----:\n   Baseline |  -- | -- | --             | *0.39* \n   CapsNet-v1 |  1 | no | 0.39 (0.024)  | *0.34 (0.032)* \n   CapsNet-v2  |  1 | yes | 0.36 (0.009)| *0.29 (0.011)*\n   CapsNet-v3 |  3 | no | 0.40 (0.016)  | *0.35 (0.036)*\n   CapsNet-v4  |  3 | yes| 0.34 (0.016) | *0.25 (0.005)*\n   \nLosses and accuracies:   \n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_356015ccbe1a.png)\n\n\n#### Training Speed \n\nAbout `100s \u002F epoch` on a single GTX 1070 GPU.   \nAbout `80s \u002F epoch` on a single GTX 1080Ti GPU.   \nAbout `55s \u002F epoch` on two GTX 1080Ti GPU by using `capsulenet-multi-gpu.py`.      \n\n#### Reconstruction result  \n\nThe result of CapsNet-v4 by launching   \n```\npython capsulenet.py -t -w result\u002Ftrained_model.h5\n```\nDigits at top 5 rows are real images from MNIST and \ndigits at bottom are corresponding reconstructed images.\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_e9385d8a559f.png)\n\n#### Manipulate latent code\n\n```\npython capsulenet.py -t --digit 5 -w result\u002Ftrained_model.h5 \n```\nFor each digit, the *i*th row corresponds to the *i*th dimension of the capsule, and columns from left to \nright correspond to adding `[-0.25, -0.2, -0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2, 0.25]` to \nthe value of one dimension of the capsule. \n\nAs we can see, each dimension has caught some characteristics of a digit. The same dimension of \ndifferent digit capsules may represent different characteristics. This is because that different \ndigits are reconstructed from different feature vectors (digit capsules). These vectors are mutually \nindependent during reconstruction.\n    \n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_97122288339b.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_fe18870ae683.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_28a875916ec4.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_c07061d9d65b.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_b80add7996a1.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_e903279b57e6.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_02cfea1cfd9b.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_a54f1115b0b8.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_486b4477c44a.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_9c3426ec317f.png)\n\n\n## Other Implementations\n\n- PyTorch:\n  - [XifengGuo\u002FCapsNet-Pytorch](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Pytorch)\n  - [timomernick\u002Fpytorch-capsule](https:\u002F\u002Fgithub.com\u002Ftimomernick\u002Fpytorch-capsule)\n  - [gram-ai\u002Fcapsule-networks](https:\u002F\u002Fgithub.com\u002Fgram-ai\u002Fcapsule-networks)\n  - [nishnik\u002FCapsNet-PyTorch](https:\u002F\u002Fgithub.com\u002Fnishnik\u002FCapsNet-PyTorch.git)\n  - [leftthomas\u002FCapsNet](https:\u002F\u002Fgithub.com\u002Fleftthomas\u002FCapsNet)\n  \n- TensorFlow:\n  - [naturomics\u002FCapsNet-Tensorflow](https:\u002F\u002Fgithub.com\u002Fnaturomics\u002FCapsNet-Tensorflow.git)   \n  I referred to some functions in this repository.\n  - [InnerPeace-Wu\u002FCapsNet-tensorflow](https:\u002F\u002Fgithub.com\u002FInnerPeace-Wu\u002FCapsNet-tensorflow)   \n  - [chrislybaer\u002Fcapsules-tensorflow](https:\u002F\u002Fgithub.com\u002Fchrislybaer\u002Fcapsules-tensorflow)\n\n- MXNet:\n  - [AaronLeong\u002FCapsNet_Mxnet](https:\u002F\u002Fgithub.com\u002FAaronLeong\u002FCapsNet_Mxnet)\n  \n- Chainer:\n  - [soskek\u002Fdynamic_routing_between_capsules](https:\u002F\u002Fgithub.com\u002Fsoskek\u002Fdynamic_routing_between_capsules)\n\n- Matlab:\n  - [yechengxi\u002FLightCapsNet](https:\u002F\u002Fgithub.com\u002Fyechengxi\u002FLightCapsNet)","# CapsNet-Keras\n[![License](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fmashape\u002Fapistatus.svg?maxAge=2592000)](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Fblob\u002Fmaster\u002FLICENSE)\n\n这是论文中CapsNet的Keras实现（分支[tf2.2](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Ftree\u002Ftf2.2)支持TensorFlow 2）：   \n[Sara Sabour, Nicholas Frosst, Geoffrey E Hinton. 动态路由在胶囊之间的应用。NIPS 2017](https:\u002F\u002Farxiv.org\u002Fabs\u002F1710.09829)   \n目前的`平均测试误差 = 0.34%`，`最佳测试误差 = 0.30%`。   \n\n**与论文的不同之处：**   \n- 我们使用了学习率衰减，衰减因子为`0.9`，每`1个epoch`衰减一次，而论文中并未给出详细参数（或者他们根本没有使用？）。  \n- 我们只报告了训练`50个epoch`后的测试误差。  \n在论文中，根据图A.1，我推测他们可能训练了`1250个epoch`？听起来有些不可思议，也许是我理解错了。  \n- 我们使用MSE（均方误差）作为重建损失，并且损失系数为`lam_recon=0.0005*784=0.392`。  \n这应该与论文中使用SSE（平方和误差）并设置`lam_recon=0.0005`是**等价**的。\n\n## 警告\n\n请使用Keras==2.0.7配合TensorFlow==1.2后端，否则`K.batch_dot`函数可能无法正常工作。\n\n然而，如果你使用**TensorFlow>=2.0**，则请检出分支[tf2.2](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Ftree\u002Ftf2.2)。\n\n\n## 使用方法\n\n**步骤1. 将本仓库克隆到本地。**\n```\ngit clone https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras.git capsnet-keras\ncd capsnet-keras\ngit checkout tf2.2 # 仅当使用TensorFlow>=2.0时\n```\n\n**步骤2. 安装Keras==2.0.7，并配置TensorFlow==1.2后端。**\n```\npip install tensorflow-gpu==1.2\npip install keras==2.0.7\n```\n**或安装TensorFlow>=2.0**\n```\npip install tensorflow==2.2\n```\n\n\n\n**步骤3. 在MNIST上训练一个CapsNet**  \n\n使用默认设置进行训练：\n```\npython capsulenet.py\n```\n\n更多详细用法可运行帮助命令：\n```\npython capsulenet.py -h\n```\n\n**步骤4. 测试一个预训练的CapsNet模型**\n\n假设你已经使用上述命令训练了一个模型，那么该模型将被保存到`result\u002Ftrained_model.h5`。现在只需运行以下命令即可获得测试结果。\n```\n$ python capsulenet.py -t -w result\u002Ftrained_model.h5\n```\n它会输出测试准确率，并展示重构后的图像。测试数据与验证数据相同。如果要对新数据进行测试，只需根据需要修改代码即可。\n\n你也可以直接从以下链接*下载我训练好的模型*：  \nhttps:\u002F\u002Fpan.baidu.com\u002Fs\u002F1sldqQo1  \n或  \nhttps:\u002F\u002Fdrive.google.com\u002Fopen?id=1A7pRxH7iWzYZekzr-O0nrwqdUUpUpkik\n\n\n**步骤5. 多GPU训练**   \n\n这需要`Keras>=2.0.9`。更新Keras后：   \n```\npython capsulenet-multi-gpu.py --gpus 2\n```\n它会自动在多张GPU上训练50个epoch，然后输出在测试集上的性能。但在训练过程中不会报告验证准确率。\n\n## 结果\n\n#### 测试误差   \n\nCapsNet在MNIST上的分类测试**误差**。平均值和标准差结果基于3次实验。可以通过运行以下命令重现这些结果。   \n ```\n python capsulenet.py --routings 1 --lam_recon 0.0    #CapsNet-v1   \n python capsulenet.py --routings 1 --lam_recon 0.392  #CapsNet-v2\n python capsulenet.py --routings 3 --lam_recon 0.0    #CapsNet-v3 \n python capsulenet.py --routings 3 --lam_recon 0.392  #CapsNet-v4\n```\n   方法     |   路由次数   |   重建   |  MNIST (%)  |  *论文*    \n   :---------|:------:|:---:|:----:|:----:\n   基线 |  -- | -- | --             | *0.39* \n   CapsNet-v1 |  1 | 否 | 0.39 (0.024)  | *0.34 (0.032)* \n   CapsNet-v2  |  1 | 是 | 0.36 (0.009)| *0.29 (0.011)*\n   CapsNet-v3 |  3 | 否 | 0.40 (0.016)  | *0.35 (0.036)*\n   CapsNet-v4  |  3 | 是| 0.34 (0.016) | *0.25 (0.005)*\n   \n损失和准确率：   \n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_356015ccbe1a.png)\n\n\n#### 训练速度 \n\n单块GTX 1070 GPU约为`100秒\u002Fepoch`。  \n单块GTX 1080Ti GPU约为`80秒\u002Fepoch`。  \n使用`capsulenet-multi-gpu.py`在两块GTX 1080Ti GPU上约为`55秒\u002Fepoch`。      \n\n#### 重构结果  \n\n通过运行以下命令得到的CapsNet-v4重构结果：   \n```\npython capsulenet.py -t -w result\u002Ftrained_model.h5\n```\n顶部5行是MNIST的真实图像，底部则是对应的重构图像。\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_e9385d8a559f.png)\n\n#### 操控潜在编码\n\n```\npython capsulenet.py -t --digit 5 -w result\u002Ftrained_model.h5 \n```\n对于每个数字，第*i*行对应胶囊的第*i*维，从左到右的列则表示向胶囊某一维的值依次添加`[-0.25, -0.2, -0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2, 0.25]`。\n\n我们可以看到，每一维都捕捉到了数字的一些特征。不同数字胶囊的同一维可能代表不同的特征。这是因为不同数字是由不同的特征向量（数字胶囊）重构出来的，而这些向量在重构过程中是相互独立的。\n    \n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_97122288339b.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_fe18870ae683.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_28a875916ec4.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_c07061d9d65b.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_b80add7996a1.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_e903279b57e6.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_02cfea1cfd9b.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_a54f1115b0b8.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_486b4477c44a.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_readme_9c3426ec317f.png)\n\n\n## 其他实现\n\n- PyTorch：\n  - [XifengGuo\u002FCapsNet-Pytorch](https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Pytorch)\n  - [timomernick\u002Fpytorch-capsule](https:\u002F\u002Fgithub.com\u002Ftimomernick\u002Fpytorch-capsule)\n  - [gram-ai\u002Fcapsule-networks](https:\u002F\u002Fgithub.com\u002Fgram-ai\u002Fcapsule-networks)\n  - [nishnik\u002FCapsNet-PyTorch](https:\u002F\u002Fgithub.com\u002Fnishnik\u002FCapsNet-PyTorch.git)\n  - [leftthomas\u002FCapsNet](https:\u002F\u002Fgithub.com\u002Fleftthomas\u002FCapsNet)\n  \n- TensorFlow：\n  - [naturomics\u002FCapsNet-Tensorflow](https:\u002F\u002Fgithub.com\u002Fnaturomics\u002FCapsNet-Tensorflow.git)   \n  我参考了该仓库中的部分函数。\n  - [InnerPeace-Wu\u002FCapsNet-tensorflow](https:\u002F\u002Fgithub.com\u002FInnerPeace-Wu\u002FCapsNet-tensorflow)   \n  - [chrislybaer\u002Fcapsules-tensorflow](https:\u002F\u002Fgithub.com\u002Fchrislybaer\u002Fcapsules-tensorflow)\n\n- MXNet：\n  - [AaronLeong\u002FCapsNet_Mxnet](https:\u002F\u002Fgithub.com\u002FAaronLeong\u002FCapsNet_Mxnet)\n  \n- Chainer：\n  - [soskek\u002Fdynamic_routing_between_capsules](https:\u002F\u002Fgithub.com\u002Fsoskek\u002Fdynamic_routing_between_capsules)\n\n- Matlab：\n  - [yechengxi\u002FLightCapsNet](https:\u002F\u002Fgithub.com\u002Fyechengxi\u002FLightCapsNet)","# CapsNet-Keras 快速上手指南\n\nCapsNet-Keras 是基于 Keras 实现的胶囊网络（Capsule Network），复现了 NIPS 2017 论文《Dynamic Routing Between Capsules》中的核心算法。该工具在 MNIST 数据集上表现优异，平均测试错误率低至 0.34%。\n\n## 环境准备\n\n本工具支持两种运行环境，请根据你的 TensorFlow 版本选择其一：\n\n*   **方案 A（推荐，现代环境）：**\n    *   TensorFlow >= 2.0 (例如 2.2)\n    *   需切换至项目的 `tf2.2` 分支\n*   **方案 B（原始环境）：**\n    *   TensorFlow == 1.2\n    *   Keras == 2.0.7\n    *   *注意：若使用此方案，必须严格匹配版本，否则 `K.batch_dot` 函数可能无法正常工作。*\n\n**硬件要求：**\n*   支持 CUDA 的 NVIDIA GPU（可选，但强烈推荐以加速训练）\n*   单卡训练速度参考：GTX 1070 约 100s\u002Fepoch，GTX 1080Ti 约 80s\u002Fepoch。\n\n## 安装步骤\n\n### 1. 克隆项目代码\n首先将仓库克隆到本地。如果你使用的是 TensorFlow 2.x，请务必切换到 `tf2.2` 分支。\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras.git capsnet-keras\ncd capsnet-keras\ngit checkout tf2.2 # 仅当使用 TensorFlow>=2.0 时执行此命令\n```\n\n### 2. 安装依赖\n根据你的环境方案执行对应的安装命令。国内用户如遇下载缓慢，可配置 pip 使用清华或阿里镜像源（例如添加 `-i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple`）。\n\n**方案 A：安装 TensorFlow 2.x 环境**\n```bash\npip install tensorflow==2.2\n```\n\n**方案 B：安装 TensorFlow 1.2 旧环境**\n```bash\npip install tensorflow-gpu==1.2\npip install keras==2.0.7\n```\n\n## 基本使用\n\n以下示例展示如何在 MNIST 数据集上进行训练和测试。\n\n### 1. 训练模型\n使用默认参数开始训练胶囊网络。训练将持续 50 个 epoch，完成后模型将保存至 `result\u002Ftrained_model.h5`。\n\n```bash\npython capsulenet.py\n```\n\n*如需查看更详细的参数选项（如调整路由次数、重建损失系数等），可运行：*\n```bash\npython capsulenet.py -h\n```\n\n### 2. 测试预训练模型\n训练完成后，或在下载了作者提供的预训练模型后，运行以下命令进行测试。该命令会输出测试准确率并生成重建图像对比。\n\n```bash\npython capsulenet.py -t -w result\u002Ftrained_model.h5\n```\n\n*注：如果没有本地模型，可从 Google Drive 或百度网盘下载作者预训练的模型文件，放置于对应路径后运行上述命令。*\n\n### 3. 多 GPU 训练（可选）\n如果你拥有多张 GPU 且已升级 Keras 至 2.0.9 以上版本，可以使用多卡加速训练：\n\n```bash\npython capsulenet-multi-gpu.py --gpus 2\n```\n*注意：多卡模式下训练过程中不会实时报告验证集准确率，仅在训练结束后输出测试结果。*","某医疗影像实验室的研究团队正致力于开发一套高精度的手写处方识别系统，以辅助医生快速录入历史病历数据。\n\n### 没有 CapsNet-Keras 时\n- **特征丢失严重**：传统卷积神经网络（CNN）在处理倾斜、重叠或局部遮挡的手写数字时，因最大池化操作丢失了关键的空间层级关系，导致识别率难以突破瓶颈。\n- **训练周期漫长**：为了复现论文中的高精度效果，团队需手动从零搭建复杂的动态路由算法，调试成本极高且容易出错，往往需要数周才能稳定模型。\n- **缺乏重建验证**：原有方案仅关注分类结果，缺少图像重建机制，无法直观判断模型是否真正“理解”了数字结构，导致误判原因难以追溯。\n- **多卡扩展困难**：在面对大规模数据集时，现有代码难以高效利用多 GPU 并行加速，单次实验耗时过长，严重拖慢研发迭代节奏。\n\n### 使用 CapsNet-Keras 后\n- **空间感知增强**：直接调用 CapsNet-Keras 实现的胶囊网络，利用动态路由机制完美保留数字的姿态和空间关系，即使在笔画粘连情况下，测试错误率也降至 0.34%。\n- **开箱即用高效**：团队只需几行命令即可在 TensorFlow 2 环境下启动训练，内置的学习率衰减和损失函数配置让模型在 50 个 epoch 内迅速收敛，大幅缩短研发周期。\n- **可视化可解释**：借助工具自带的重建损失功能，系统能实时输出还原后的清晰图像，研究人员可直观确认模型捕捉到了正确的笔触特征，提升了调优效率。\n- **弹性算力支持**：通过简单的参数调整即可切换至多 GPU 训练模式，将单轮训练时间从百秒级压缩至更低，显著加快了超参数搜索和模型验证过程。\n\nCapsNet-Keras 将前沿的胶囊理论转化为工程利器，让研究团队能以极低的门槛获得超越传统 CNN 的识别精度与可解释性。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FXifengGuo_CapsNet-Keras_356015cc.png","XifengGuo","Xifeng Guo","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FXifengGuo_c8832ac8.jpg","My interests include Clustering, Deep Learning, Representation Learning and Transfer Learning.","NUDT",null,"https:\u002F\u002Fxifengguo.github.io","https:\u002F\u002Fgithub.com\u002FXifengGuo",[82],{"name":83,"color":84,"percentage":85},"Python","#3572A5",100,2460,647,"2026-04-07T04:02:45","MIT","未说明","训练部分可选但推荐（支持多 GPU），文中测试环境为 GTX 1070 或 GTX 1080Ti；若使用 TensorFlow 1.2 需安装 tensorflow-gpu",{"notes":93,"python":90,"dependencies":94},"该工具对版本有严格限制：若使用 TensorFlow 1.x，必须指定 Keras==2.0.7 和 TensorFlow==1.2，否则 K.batch_dot 函数可能无法正常工作；若使用 TensorFlow 2.0+，必须切换到代码库的 tf2.2 分支。多 GPU 训练功能需要 Keras 版本升级至 2.0.9 以上。",[95,96,97,98],"tensorflow-gpu==1.2 (配合 Keras 2.0.7)","keras==2.0.7","tensorflow>=2.2 (替代方案，需切换至 tf2.2 分支)","keras>=2.0.9 (仅用于多 GPU 训练)",[15,14],[101,102,103,104,105,106],"keras","capsnet","capsule","capsnet-keras","capsule-network","dynamic-routing","2026-03-27T02:49:30.150509","2026-04-08T13:59:05.219802",[110,115,120,125,130,135],{"id":111,"question_zh":112,"answer_zh":113,"source_url":114},24454,"运行代码时遇到 'GraphViz executables not found' 或 'Failed to import pydot' 错误，即使已安装相关包怎么办？","这是常见的环境配置问题。请尝试以下解决方案：\n1. 确保安装了所有必要包：`pip install pydot pydotplus graphviz` 或使用 conda：`conda install graphviz`。\n2. Windows 用户特别注意：安装 Graphviz 二进制文件后，必须将其添加到系统 %PATH% 环境变量中，并且**必须重启 Jupyter Notebook 服务器**（不仅仅是重启内核），因为 Windows 会在 Shell 启动时缓存 %PATH%。\n3. Mac\u002FLinux 用户如果仍报错，可以在代码中手动指定 pydot 后端：\n   ```python\n   import pydotplus\n   import keras\n   keras.utils.vis_utils.pydot = pydotplus\n   plot_model(model, to_file='model.png')\n   ```\n4. 如果在 Jupyter 中不想重启服务器，可以尝试重载模块：\n   ```python\n   import keras.utils.vis_utils\n   from importlib import reload\n   reload(keras.utils.vis_utils)\n   ```","https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Fissues\u002F7",{"id":116,"question_zh":117,"answer_zh":118,"source_url":119},24455,"遇到 ValueError: Can not do batch_dot on inputs with shapes... 形状不匹配错误如何解决？","该问题是由 Keras 版本更新导致 `keras.backend.batch_dot` 行为变化引起的。在旧版本中维度计算正常，但在新版本中会产生额外的维度。\n解决方案是将代码中的 `K.batch_dot` 替换为 `tf.matmul`。维护者已提供修复后的代码逻辑，建议参考官方仓库中 `capsulelayers.py` 文件的最新实现（特别是第 120-163 行），或者手动修改调用方式以适配新版 TensorFlow\u002FKeras 的矩阵乘法规则。","https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Fissues\u002F104",{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},24456,"已经安装了 pydot 和 graphviz，但仍然报 ImportError 提示需要安装它们，该怎么办？","这通常是因为环境中存在多个版本的绘图库冲突，或者路径未刷新。请按顺序执行以下步骤：\n1. 显式安装 `pydotplus`，很多时候缺少的是这个包：`pip install pydotplus`。\n2. 如果使用 Conda 环境，尝试使用 `conda install graphviz` 重新安装 graphviz。\n3. 确保安装顺序为：先安装 graphviz 系统包，再安装 python 包装器（pydot, pydotplus）。\n4. 如果是 Windows 用户，检查是否将 Graphviz 的 bin 目录加入了 PATH 并重启了终端或 IDE。","https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Fissues\u002F25",{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},24457,"在 CIFAR-10 数据集上训练 Capsule Network 准确率很低（约 54%）且不再提升，是参数设置问题吗？","复现论文结果在 CIFAR-10 上确实具有挑战性。用户反馈表明，默认参数可能无法直接达到论文声称的 90%+ 准确率。\n1. 检查卷积核大小和 Primary Capsule 的数量设置，有用户尝试将卷积核设为 24，Primary Capsule size 设为 64，但仍可能在 14 个 epoch 后停滞。\n2. 社区指出，原始的 CapsNet 架构在复杂数据集（如 CIFAR-10\u002F100）上的表现可能不如在 MNIST 上稳定，重建效果也较差。\n3. 建议参考后续改进的架构，例如 CVPR 2019 提出的 Deep Capsule Networks (DeepCaps)，其实现可能在复杂数据集上表现更好。","https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Fissues\u002F10",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},24458,"在 Ubuntu 虚拟环境中如何正确安装 pydot 以避免导入错误？","在 Ubuntu 的虚拟环境（如 conda 或 venv）中，请遵循以下步骤确保安装正确：\n1. 激活你的虚拟环境：`conda activate 你的环境名` 或 `source venv\u002Fbin\u002Factivate`。\n2. 在终端中使用 python 模块方式安装：`python -m pip install pydot`。\n3. 安装完成后，使用 `pip list` 确认包已存在于当前环境中。\n这种方法可以避免将包安装到全局环境而虚拟环境无法识别的问题。","https:\u002F\u002Fgithub.com\u002FXifengGuo\u002FCapsNet-Keras\u002Fissues\u002F69",{"id":136,"question_zh":137,"answer_zh":138,"source_url":114},24459,"Mac M1 芯片环境下运行模型可视化报错，有什么特定的解决方案吗？","在 Mac M1 (miniforge3) 环境下，即使安装了标准包也可能报错。成功的解决方案包括：\n1. 确保安装特定版本的包组合：`pydot==1.4.2`, `pydot-ng==2.0.0`, `pydotplus==2.0.2`, `keras==2.9.0`, `python==3.10.5`。\n2. 在代码开头显式导入并替换后端：\n   ```python\n   import pydotplus\n   import keras\n   keras.utils.vis_utils.pydot = pydotplus\n   ```\n3. 不需要修改 keras 源文件 `vis_utils.py`，只需在脚本或 Notebook 中运行上述赋值语句即可生效。",[140],{"id":141,"version":142,"summary_zh":143,"released_at":144},154008,"v0.1","仅用于实验目的。可通过调参来提升性能。","2017-11-03T02:49:19"]