[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-lucasb-eyer--pydensecrf":3,"tool-lucasb-eyer--pydensecrf":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":82,"owner_website":83,"owner_url":84,"languages":85,"stars":105,"forks":106,"last_commit_at":107,"license":108,"difficulty_score":109,"env_os":110,"env_gpu":111,"env_ram":111,"env_deps":112,"category_tags":118,"github_topics":119,"view_count":23,"oss_zip_url":82,"oss_zip_packed_at":82,"status":16,"created_at":127,"updated_at":128,"faqs":129,"releases":158},3580,"lucasb-eyer\u002Fpydensecrf","pydensecrf","Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.","pydensecrf 是一个高效的 Python 封装库，旨在让开发者轻松调用 Philipp Krähenbühl 提出的全连接条件随机场（Dense CRF）算法。它主要解决计算机视觉中图像分割结果不够精细的问题：深度学习模型输出的分割图往往边界模糊或存在噪点，而 pydensecrf 能利用像素间的颜色相似性和空间邻近性进行后处理优化，使物体边缘更加清晰、贴合真实轮廓。\n\n该工具特别适合从事图像分割研究的科研人员、算法工程师以及需要提升模型输出质量的深度学习开发者。其核心技术亮点在于实现了带有高斯边势的全连接 CRF 高效推理，通过 Cython 加速底层 C++ 代码，在保持高精度的同时显著提升了计算速度。使用时，用户只需提供神经网络输出的概率分布（一元势），即可快速获得优化后的分割结果。虽然安装过程在部分 Windows 环境下可能需要额外配置编译环境，但其简洁的 API 设计和完善的工具函数（如直接从 Softmax 输出构建势能）极大地降低了使用门槛，是提升语义分割效果的经典利器。","PyDenseCRF\n==========\n\nThis is a (Cython-based) Python wrapper for [Philipp Krähenbühl's Fully-Connected CRFs](http:\u002F\u002Fweb.archive.org\u002Fweb\u002F20161023180357\u002Fhttp:\u002F\u002Fwww.philkr.net\u002Fhome\u002Fdensecrf) (version 2, [new, incomplete page](http:\u002F\u002Fwww.philkr.net\u002F2011\u002F12\u002F01\u002Fnips\u002F)).\n\nIf you use this code for your reasearch, please cite:\n\n```\nEfficient Inference in Fully Connected CRFs with Gaussian Edge Potentials\nPhilipp Krähenbühl and Vladlen Koltun\nNIPS 2011\n```\n\nand provide a link to this repository as a footnote or a citation.\n\nInstallation\n============\n\nThe package is on PyPI, so simply run `pip install pydensecrf` to install it.\n\nIf you want the newest and freshest version, you can install it by executing:\n\n```\npip install git+https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf.git\n```\n\nand ignoring all the warnings coming from Eigen.\n\nNote that you need a relatively recent version of Cython (at least version 0.22) for this wrapper,\nthe one shipped with Ubuntu 14.04 is too old. (Thanks to Scott Wehrwein for pointing this out.)\nI suggest you use a [virtual environment](https:\u002F\u002Fvirtualenv.readthedocs.org\u002Fen\u002Flatest\u002F) and install\nthe newest version of Cython there (`pip install cython`), but you may update the system version by\n\n```\nsudo apt-get remove cython\nsudo pip install -U cython\n```\n\n### Problems on Windows\u002FVS\n\nSince this library needs to compile C++ code, installation can be a little more problematic than pure Python packages.\nMake sure to [have Cython installed](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F62#issuecomment-400563257) or try [installing via conda instead](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F69#issuecomment-400639881) if you are getting problems.\nPRs that improve Windows support are welcome.\n\n### Problems on Colab\u002FKaggle Kernel\n\n`pydensecrf` does not come pre-installed in Colab or Kaggle Kernel. Running `pip install pydensecrf` will result into\nbuild failures. Follow these steps instead for Colab\u002FKaggle Kernel:\n\n```\npip install -U cython\npip install git+https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf.git\n```\n\nUsage\n=====\n\nFor images, the easiest way to use this library is using the `DenseCRF2D` class:\n\n```python\nimport numpy as np\nimport pydensecrf.densecrf as dcrf\n\nd = dcrf.DenseCRF2D(640, 480, 5)  # width, height, nlabels\n```\n\nUnary potential\n---------------\n\nYou can then set a fixed unary potential in the following way:\n\n```python\nU = np.array(...)     # Get the unary in some way.\nprint(U.shape)        # -> (5, 480, 640)\nprint(U.dtype)        # -> dtype('float32')\nU = U.reshape((5,-1)) # Needs to be flat.\nd.setUnaryEnergy(U)\n\n# Or alternatively: d.setUnary(ConstUnary(U))\n```\n\nRemember that `U` should be negative log-probabilities, so if you're using\nprobabilities `py`, don't forget to `U = -np.log(py)` them.\n\nRequiring the `reshape` on the unary is an API wart that I'd like to fix, but\ndon't know how to without introducing an explicit dependency on numpy.\n\n**Note** that the `nlabels` dimension is the first here before the reshape;\nyou may need to move it there before reshaping if that's not already the case,\nlike so:\n\n```python\nprint(U.shape)  # -> (480, 640, 5)\nU = U.transpose(2, 0, 1).reshape((5,-1))\n```\n\n### Getting a Unary\n\nThere's two common ways of getting unary potentials:\n\n1. From a hard labeling generated by a human or some other processing.\n   This case is covered by `from pydensecrf.utils import unary_from_labels`.\n\n2. From a probability distribution computed by, e.g. the softmax output of a\n   deep network. For this, see `from pydensecrf.utils import unary_from_softmax`.\n\nFor usage of both of these, please refer to their docstrings or have a look at [the example](examples\u002Finference.py).\n\nPairwise potentials\n-------------------\n\nThe two-dimensional case has two utility methods for adding the most-common pairwise potentials:\n\n```python\n# This adds the color-independent term, features are the locations only.\nd.addPairwiseGaussian(sxy=(3,3), compat=3, kernel=dcrf.DIAG_KERNEL, normalization=dcrf.NORMALIZE_SYMMETRIC)\n\n# This adds the color-dependent term, i.e. features are (x,y,r,g,b).\n# im is an image-array, e.g. im.dtype == np.uint8 and im.shape == (640,480,3)\nd.addPairwiseBilateral(sxy=(80,80), srgb=(13,13,13), rgbim=im, compat=10, kernel=dcrf.DIAG_KERNEL, normalization=dcrf.NORMALIZE_SYMMETRIC)\n```\n\nBoth of these methods have shortcuts and default-arguments such that the most\ncommon use-case can be simplified to:\n\n```python\nd.addPairwiseGaussian(sxy=3, compat=3)\nd.addPairwiseBilateral(sxy=80, srgb=13, rgbim=im, compat=10)\n```\n\nThe parameters map to those in the paper as follows: `sxy` in the `Gaussian` case is `$\\theta_{\\gamma}$`,\nand in the `Bilateral` case, `sxy` and `srgb` map to `$\\theta_{\\alpha}$` and `$\\theta_{\\beta}$`, respectively.\nThe names are shorthand for \"x\u002Fy standard-deviation\" and \"rgb standard-deviation\" and for reference, the formula is:\n\n![Equation 3 in the original paper](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flucasb-eyer_pydensecrf_readme_cdc256c06b92.png)\n\n### Non-RGB bilateral\n\nAn important caveat is that `addPairwiseBilateral` only works for RGB images, i.e. three channels.\nIf your data is of different type than this simple but common case, you'll need to compute your\nown pairwise energy using `utils.create_pairwise_bilateral`; see the [generic non-2D case](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#generic-non-2d) for details.\n\nA good [example of working with Non-RGB data](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fblob\u002Fmaster\u002Fexamples\u002FNon%20RGB%20Example.ipynb) is provided as a notebook in the examples folder.\n\n### Compatibilities\n\nThe `compat` argument can be any of the following:\n\n- A number, then a `PottsCompatibility` is being used.\n- A 1D array, then a `DiagonalCompatibility` is being used.\n- A 2D array, then a `MatrixCompatibility` is being used.\n\nThese are label-compatibilites `µ(xi, xj)` whose parameters could possibly be [learned](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#learning).\nFor example, they could indicate that mistaking `bird` pixels for `sky` is not as bad as mistaking `cat` for `sky`.\nThe arrays should have `nlabels` or `(nlabels,nlabels)` as shape and a `float32` datatype.\n\n### Kernels\n\nPossible values for the `kernel` argument are:\n\n- `CONST_KERNEL`\n- `DIAG_KERNEL` (the default)\n- `FULL_KERNEL`\n\nThis specifies the kernel's precision-matrix `Λ(m)`, which could possibly be learned.\nThese indicate correlations between feature types, the default implying no correlation.\nAgain, this could possiblty be [learned](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#learning).\n\n### Normalizations\n\nPossible values for the `normalization` argument are:\n\n- `NO_NORMALIZATION`\n- `NORMALIZE_BEFORE`\n- `NORMALIZE_AFTER`\n- `NORMALIZE_SYMMETRIC` (the default)\n\n### Kernel weight\n\nI have so far not found a way to set the kernel weights `w(m)`.\nAccording to the paper, `w(2)` was set to 1 and `w(1)` was cross-validated, but never specified.\nLooking through Philip's code (included in [pydensecrf\u002Fdensecrf](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Ftree\u002Fmaster\u002Fpydensecrf\u002Fdensecrf)),\nI couldn't find such explicit weights, and my guess is they are thus hard-coded to 1.\nIf anyone knows otherwise, please open an issue or, better yet, a pull-request.\nUpdate: user @waldol1 has an idea in [this issue](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F37). Feel free to try it out!\n\nInference\n---------\n\nThe easiest way to do inference with 5 iterations is to simply call:\n\n```python\nQ = d.inference(5)\n```\n\nAnd the MAP prediction is then:\n\n```python\nmap = np.argmax(Q, axis=0).reshape((640,480))\n```\n\nIf you're interested in the class-probabilities `Q`, you'll notice `Q` is a\nwrapped Eigen matrix. The Eigen wrappers of this project implement the buffer\ninterface and can be simply cast to numpy arrays like so:\n\n```python\nproba = np.array(Q)\n```\n\nStep-by-step inference\n----------------------\n\nIf for some reason you want to run the inference loop manually, you can do so:\n\n```python\nQ, tmp1, tmp2 = d.startInference()\nfor i in range(5):\n    print(\"KL-divergence at {}: {}\".format(i, d.klDivergence(Q)))\n    d.stepInference(Q, tmp1, tmp2)\n```\n\nGeneric non-2D\n--------------\n\nThe `DenseCRF` class can be used for generic (non-2D) dense CRFs.\nIts usage is exactly the same as above, except that the 2D-specific pairwise\npotentials `addPairwiseGaussian` and `addPairwiseBilateral` are missing.\n\nInstead, you need to use the generic `addPairwiseEnergy` method like this:\n\n```python\nd = dcrf.DenseCRF(100, 5)  # npoints, nlabels\n\nfeats = np.array(...)  # Get the pairwise features from somewhere.\nprint(feats.shape)     # -> (7, 100) = (feature dimensionality, npoints)\nprint(feats.dtype)     # -> dtype('float32')\n\ndcrf.addPairwiseEnergy(feats)\n```\n\nIn addition, you can pass `compatibility`, `kernel` and `normalization`\narguments just like in the 2D gaussian and bilateral cases.\n\nThe potential will be computed as `w*exp(-0.5 * |f_i - f_j|^2)`.\n\n### Pairwise potentials for N-D\n\nUser @markusnagel has written a couple numpy-functions generalizing the two\nclassic 2-D image pairwise potentials (gaussian and bilateral) to an arbitrary\nnumber of dimensions: `create_pairwise_gaussian` and `create_pairwise_bilateral`.\nYou can access them as `from pydensecrf.utils import create_pairwise_gaussian`\nand then have a look at their docstring to see how to use them.\n\nLearning\n--------\n\nThe learning has not been fully wrapped. If you need it, get in touch or better\nyet, wrap it and submit a pull-request!\n\nHere's a pointer for starters: issue#24. We need to wrap the gradients and getting\u002Fsetting parameters.\nBut then, we also need to do something with these, most likely call [minimizeLBFGS from optimization.cpp](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fblob\u002Fd824b89ee3867bca3e90b9f04c448f1b41821524\u002Fpydensecrf\u002Fdensecrf\u002Fsrc\u002Foptimization.cpp).\nIt should be relatively straightforward to just follow the learning examples included in the [original code](http:\u002F\u002Fgraphics.stanford.edu\u002Fprojects\u002Fdrf\u002Fdensecrf_v_2_2.zip).\n\nCommon Problems\n===============\n\n`undefined symbol` when importing\n---------------------------------\n\nIf while importing pydensecrf you get an error about some undefined symbols (for example `...\u002Fpydensecrf\u002Fdensecrf.so: undefined symbol: _ZTINSt8ios_base7failureB5cxx11E`), you most likely are inadvertently mixing different compilers or toolchains. Try to see what's going on using tools like `ldd`. If you're using Anaconda, [running `conda install libgcc` might be a solution](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F28).\n\nValueError: Buffer dtype mismatch, expected 'float' but got 'double'\n--------------------------------------------------------------------\n\nThis is a pretty [co](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F52)mm[on](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F49) user error.\nIt means exactly what it says: you are passing a `double` but it wants a `float`.\nSolve it by, for example, calling `d.setUnaryEnergy(U.astype(np.float32))` instead of just `d.setUnaryEnergy(U)`, or using `float32` in your code in the first place.\n\nMy results are all pixelated like [MS Paint's airbrush tool](http:\u002F\u002Flmgtfy.com\u002F?q=MS+Paint+Airbrush+tool)!\n----------------------------------------------------------\n\nYou screwed up reshaping somewhere and treated the class\u002Flabel dimension as spatial dimension.\nThis is you misunderstanding NumPy's memory layout and nothing that PyDenseCRF can detect or help with.\n\nThis mistake often happens for the Unary, see the [**Note** in that section of the README](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#unary-potential).\n\n\nMaintaining\n===========\n\nThese are instructions for maintainers about how to release new versions. (Mainly instructions for myself.)\n\n```\n# Go increment the version in setup.py\n> python setup.py build_ext\n> python setup.py sdist\n> twine upload dist\u002Fpydensecrf-VERSION_NUM.tar.gz\n```\n\nAnd that's it. At some point, it would be cool to automate this on [TravisCI](https:\u002F\u002Fdocs.travis-ci.com\u002Fuser\u002Fdeployment\u002Fpypi\u002F), but not worth it yet.\nAt that point, looking into [creating \"manylinux\" wheels](https:\u002F\u002Fgithub.com\u002Fpypa\u002Fpython-manylinux-demo) might be nice, too.\n\nTesting\n=======\n\nThanks to @MarvinTeichmann we now have proper tests, install the package and run `py.test`.\nMaybe there's a better way to run them, but both of us don't know :smile:\n","PyDenseCRF\n==========\n\n这是一个基于 Cython 的 Python 封装库，用于 Philipp Krähenbühl 的全连接条件随机场（版本 2，[新页面，尚未完成](http:\u002F\u002Fwww.philkr.net\u002F2011\u002F12\u002F01\u002Fnips\u002F)）。\n\n如果您在研究中使用此代码，请引用以下文献：\n\n```\n高效全连接条件随机场中的高斯边势能推断\nPhilipp Krähenbühl 和 Vladlen Koltun\nNIPS 2011\n```\n\n并在脚注或参考文献中提供本仓库的链接。\n\n安装\n====\n\n该包已在 PyPI 上发布，因此只需运行 `pip install pydensecrf` 即可安装。\n\n如果您希望使用最新版本，可以执行以下命令进行安装：\n\n```\npip install git+https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf.git\n```\n\n并忽略来自 Eigen 的所有警告。\n\n请注意，此封装需要相对较新的 Cython 版本（至少 0.22），而 Ubuntu 14.04 自带的版本过旧。（感谢 Scott Wehrwein 指出这一点。）建议您使用 [虚拟环境](https:\u002F\u002Fvirtualenv.readthedocs.org\u002Fen\u002Flatest\u002F) 并在其中安装最新版 Cython (`pip install cython`)，或者通过以下命令更新系统自带的 Cython 版本：\n\n```\nsudo apt-get remove cython\nsudo pip install -U cython\n```\n\n### Windows\u002FVS 上的问题\n\n由于该库需要编译 C++ 代码，因此其安装可能比纯 Python 包更为复杂。请确保已安装 Cython，或者如果遇到问题，可以尝试使用 [conda 进行安装](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F69#issuecomment-400639881)。欢迎提交改进 Windows 支持的 Pull Request。\n\n### Colab\u002FKaggle Kernel 上的问题\n\n`pydensecrf` 在 Colab 或 Kaggle Kernel 中并未预装。直接运行 `pip install pydensecrf` 会导致构建失败。对于 Colab\u002FKaggle Kernel，请按照以下步骤操作：\n\n```\npip install -U cython\npip install git+https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf.git\n```\n\n使用方法\n========\n\n对于图像，使用此库最简单的方式是使用 `DenseCRF2D` 类：\n\n```python\nimport numpy as np\nimport pydensecrf.densecrf as dcrf\n\nd = dcrf.DenseCRF2D(640, 480, 5)  # 宽度、高度、类别数\n```\n\n一元势能\n--------\n\n随后，您可以按如下方式设置固定的一元势能：\n\n```python\nU = np.array(...)     # 以某种方式获取一元势能。\nprint(U.shape)        # -> (5, 480, 640)\nprint(U.dtype)        # -> dtype('float32')\nU = U.reshape((5,-1)) # 需要展平。\nd.setUnaryEnergy(U)\n\n# 或者：d.setUnary(ConstUnary(U))\n```\n\n请记住，`U` 应为负对数概率，因此如果您使用的是概率值 `py`，别忘了将其转换为 `U = -np.log(py)`。\n\n要求一元势能进行 `reshape` 是一个 API 设计上的小瑕疵，我希望未来能够修复，但目前尚不清楚如何在不引入对 NumPy 显式依赖的情况下实现这一点。\n\n**注意**，在 `reshape` 之前，`nlabels` 维度位于数组的第一位；如果未处于该位置，您可能需要先将其移动到第一位再进行 `reshape`，例如：\n\n```python\nprint(U.shape)  # -> (480, 640, 5)\nU = U.transpose(2, 0, 1).reshape((5,-1))\n```\n\n### 获取一元势能的方法\n\n获取一元势能通常有两种常见方式：\n\n1. 由人工标注或其他处理生成的硬标签。这种情况可以使用 `from pydensecrf.utils import unary_from_labels`。\n\n2. 由深度网络的 softmax 输出等计算得到的概率分布。对此，可以使用 `from pydensecrf.utils import unary_from_softmax`。\n\n有关这两种方法的具体用法，请参阅其文档字符串，或查看 [示例](examples\u002Finference.py)。\n\n成对势能\n---------\n\n在二维情况下，有两个实用方法可用于添加最常见的成对势能：\n\n```python\n# 添加与颜色无关的项，特征仅包括位置信息。\nd.addPairwiseGaussian(sxy=(3,3), compat=3, kernel=dcrf.DIAG_KERNEL, normalization=dcrf.NORMALIZE_SYMMETRIC)\n\n# 添加与颜色相关的项，即特征包括 (x,y,r,g,b)。\n# im 是图像数组，例如 im.dtype == np.uint8 且 im.shape == (640,480,3)\nd.addPairwiseBilateral(sxy=(80,80), srgb=(13,13,13), rgbim=im, compat=10, kernel=dcrf.DIAG_KERNEL, normalization=dcrf.NORMALIZE_SYMMETRIC)\n```\n\n这两种方法都提供了简写和默认参数，使得最常见的用法可以简化为：\n\n```python\nd.addPairwiseGaussian(sxy=3, compat=3)\nd.addPairwiseBilateral(sxy=80, srgb=13, rgbim=im, compat=10)\n```\n\n这些参数与论文中的对应关系如下：在“Gaussian”情况下，`sxy` 对应于 `$\\theta_{\\gamma}$`；而在“Bilateral”情况下，`sxy` 和 `srgb` 分别对应于 `$\\theta_{\\alpha}$` 和 `$\\theta_{\\beta}$`。这些名称分别是“x\u002Fy 标准差”和“RGB 标准差”的缩写，公式如下：\n\n![原始论文中的公式 3](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flucasb-eyer_pydensecrf_readme_cdc256c06b92.png)\n\n### 非 RGB 双边势能\n\n需要注意的是，`addPairwiseBilateral` 仅适用于 RGB 图像，即具有三个通道的图像。如果您的数据类型与此不同，则需要使用 `utils.create_pairwise_bilateral` 来计算自定义的成对能量。详细信息请参阅 [通用非二维情况](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#generic-non-2d)。\n\n示例文件夹中提供了一个关于 [非 RGB 数据处理的良好示例](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fblob\u002Fmaster\u002Fexamples\u002FNon%20RGB%20Example.ipynb)，以笔记本形式呈现。\n\n### 兼容性\n\n`compat` 参数可以是以下几种类型：\n\n- 数字：此时使用的是 Potts 兼容性。\n- 一维数组：此时使用的是对角兼容性。\n- 二维数组：此时使用的是矩阵兼容性。\n\n这些表示标签之间的兼容性 `µ(xi, xj)`，其参数可以通过 [学习](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#learning) 来确定。例如，它们可以表明将“鸟”像素误判为“天空”并不如将“猫”误判为“天空”那样严重。这些数组的形状应为 `nlabels` 或 `(nlabels,nlabels)`，数据类型为 `float32`。\n\n### 核函数\n\n`kernel` 参数的取值包括：\n\n- `CONST_KERNEL`\n- `DIAG_KERNEL`（默认）\n- `FULL_KERNEL`\n\n这决定了核的精度矩阵 `Λ(m)`，其参数同样可以通过学习来优化。这些参数反映了特征类型之间的相关性，默认值表示无相关性。再次强调，这些参数也可以通过 [学习](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#learning) 来确定。\n\n### 归一化\n\n`normalization` 参数的取值包括：\n\n- `NO_NORMALIZATION`\n- `NORMALIZE_BEFORE`\n- `NORMALIZE_AFTER`\n- `NORMALIZE_SYMMETRIC`（默认）\n\n### 核权重\n\n到目前为止，我还没有找到设置核权重 `w(m)` 的方法。根据论文，`w(2)` 被设为 1，而 `w(1)` 则通过交叉验证确定，但并未明确说明具体值。在查看 Philip 的代码（包含在 [pydensecrf\u002Fdensecrf](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Ftree\u002Fmaster\u002Fpydensecrf\u002Fdensecrf) 中）时，我也没有发现显式的权重设置，因此我猜测这些权重被硬编码为 1。如果有人知道其他情况，请提交一个问题，或者更好的是，提交一个拉取请求。\n\n更新：用户 @waldol1 在 [这个问题](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F37) 中提出了一种想法，欢迎大家尝试！\n\n推理\n---------\n\n使用 5 次迭代进行推理的最简单方法就是直接调用：\n\n```python\nQ = d.inference(5)\n```\n\n然后，最大后验预测结果为：\n\n```python\nmap = np.argmax(Q, axis=0).reshape((640,480))\n```\n\n如果你对类别概率 `Q` 感兴趣，你会发现 `Q` 是一个封装的 Eigen 矩阵。该项目的 Eigen 封装实现了缓冲区接口，可以像下面这样简单地转换为 NumPy 数组：\n\n```python\nproba = np.array(Q)\n```\n\n逐步推理\n----------------------\n\n如果你出于某种原因想要手动运行推理循环，可以这样做：\n\n```python\nQ, tmp1, tmp2 = d.startInference()\nfor i in range(5):\n    print(\"KL散度在第 {} 次迭代时为: {}\".format(i, d.klDivergence(Q)))\n    d.stepInference(Q, tmp1, tmp2)\n```\n\n通用非二维\n--------------\n\n`DenseCRF` 类可用于通用（非二维）密集条件随机场。其用法与上述完全相同，只是缺少专门针对二维的成对势能函数 `addPairwiseGaussian` 和 `addPairwiseBilateral`。\n\n相反，你需要使用通用的 `addPairwiseEnergy` 方法，如下所示：\n\n```python\nd = dcrf.DenseCRF(100, 5)  # 点数，标签数\n\nfeats = np.array(...)  # 从某处获取成对特征。\nprint(feats.shape)     # -> (7, 100) = (特征维度，点数)\nprint(feats.dtype)     # -> dtype('float32')\n\ndcrf.addPairwiseEnergy(feats)\n```\n\n此外，你还可以像在二维高斯和双边情况下一样，传递 `compatibility`、`kernel` 和 `normalization` 参数。\n\n势能将按照 `w*exp(-0.5 * |f_i - f_j|^2)` 计算。\n\n### N 维的成对势能\n\n用户 @markusnagel 编写了几个 NumPy 函数，将经典的两种二维图像成对势能（高斯和双边）推广到任意维度：`create_pairwise_gaussian` 和 `create_pairwise_bilateral`。你可以通过 `from pydensecrf.utils import create_pairwise_gaussian` 来访问它们，并查看其文档字符串以了解如何使用。\n\n学习\n--------\n\n学习功能尚未完全封装。如果你需要它，请联系我们，或者更好的是，自行封装并提交一个拉取请求！\n\n这里有一个入门提示：问题#24。我们需要封装梯度以及参数的获取和设置。之后，我们还需要对这些数据做进一步处理，很可能需要调用 [optimization.cpp 中的 minimizeLBFGS](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fblob\u002Fd824b89ee3867bca3e90b9f04c448f1b41821524\u002Fpydensecrf\u002Fdensecrf\u002Fsrc\u002Foptimization.cpp)。只需按照 [原始代码](http:\u002F\u002Fgraphics.stanford.edu\u002Fprojects\u002Fdrf\u002Fdensecrf_v_2_2.zip) 中包含的学习示例操作，应该会相对简单。\n\n常见问题\n===============\n\n导入时出现“未定义符号”错误\n---------------------------------\n\n如果你在导入 pydensecrf 时遇到关于某些未定义符号的错误（例如 `...\u002Fpydensecrf\u002Fdensecrf.so: undefined symbol: _ZTINSt8ios_base7failureB5cxx11E`），很可能是无意中混用了不同的编译器或工具链。可以使用 `ldd` 等工具来检查具体情况。如果你使用的是 Anaconda，[运行 `conda install libgcc` 可能是一个解决方案](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F28)。\n\nValueError: 缓冲区数据类型不匹配，期望 'float' 却得到 'double'\n--------------------------------------------------------------------\n\n这是一种相当常见的用户错误。它的意思就是字面意思：你传递了一个 `double` 类型的数据，但函数期望的是 `float` 类型。解决办法是，例如，调用 `d.setUnaryEnergy(U.astype(np.float32))` 而不是直接调用 `d.setUnaryEnergy(U)`，或者在代码一开始就使用 `float32` 数据类型。\n\n我的结果全都像 [MS Paint 的喷枪工具](http:\u002F\u002Flmgtfy.com\u002F?q=MS+Paint+Airbrush+tool) 一样像素化！\n----------------------------------------------------------\n\n你在某个地方搞错了形状重塑，把类别\u002F标签维度当成了空间维度。这是你对 NumPy 内存布局的理解出现了偏差，而 PyDenseCRF 无法检测或帮助解决这个问题。\n\n这种错误通常发生在单体势能部分，详见 [README 中该部分的**注释**](https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf#unary-potential)。\n\n维护\n===========\n\n以下是一些面向维护者的发布新版本的说明。（主要是给自己看的。）\n\n```\n# 去 setup.py 中将版本号递增\n> python setup.py build_ext\n> python setup.py sdist\n> twine upload dist\u002Fpydensecrf-VERSION_NUM.tar.gz\n```\n\n就这样。将来可以在 [TravisCI](https:\u002F\u002Fdocs.travis-ci.com\u002Fuser\u002Fdeployment\u002Fpypi\u002F) 上实现自动化部署，但现在还不值得。届时，也可以考虑 [创建 \"manylinux\" 轮子](https:\u002F\u002Fgithub.com\u002Fpypa\u002Fpython-manylinux-demo)，那会是个不错的想法。\n\n测试\n=======\n\n感谢 @MarvinTeichmann，我们现在有了完善的测试。安装包后运行 `py.test` 即可。也许还有更好的运行方式，但我们俩都不太清楚 :smile:","# PyDenseCRF 快速上手指南\n\nPyDenseCRF 是 Philipp Krähenbühl 提出的全连接条件随机场（Fully-Connected CRFs）的 Python 封装（基于 Cython），常用于图像分割任务的后处理，以优化边缘细节。\n\n## 环境准备\n\n*   **系统要求**：支持 Linux、macOS 和 Windows。\n    *   *注意*：Windows 用户需确保已安装支持 C++ 编译的工具链（如 Visual Studio Build Tools），或直接使用 Conda 安装。\n*   **前置依赖**：\n    *   Python 3.x\n    *   NumPy\n    *   Cython（版本需 >= 0.22，旧版 Ubuntu 自带版本过低，建议升级）\n    *   C++ 编译器（用于编译底层 C++ 代码）\n\n## 安装步骤\n\n### 方法一：通过 PyPI 安装（推荐）\n最简便的方式是使用 pip 直接安装预编译包或源码包：\n\n```bash\npip install pydensecrf\n```\n\n> **国内加速建议**：如果下载速度慢，可使用清华或阿里镜像源：\n> ```bash\n> pip install pydensecrf -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n> ```\n\n### 方法二：安装最新开发版\n如需获取最新功能，可从 GitHub 源码安装：\n\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf.git\n```\n\n### 特殊环境安装\n\n**1. Windows 用户**\n若 `pip` 安装失败（通常因缺少编译器），建议使用 Conda：\n```bash\nconda install -c conda-forge pydensecrf\n```\n\n**2. Colab \u002F Kaggle 环境**\n这些环境未预装该库且直接 pip 安装可能报错，请按顺序执行以下命令：\n```bash\npip install -U cython\npip install git+https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf.git\n```\n\n## 基本使用\n\n以下是针对二维图像的最简使用流程，包含初始化、设置势能、添加成对项及推理。\n\n### 1. 初始化与一元势能 (Unary Potential)\n一元势能通常来自深度学习模型的输出（如 Softmax 概率）。**注意**：CRF 需要负对数概率作为输入，且数据维度需调整为 `(nlabels, -1)`。\n\n```python\nimport numpy as np\nimport pydensecrf.densecrf as dcrf\nfrom pydensecrf.utils import unary_from_softmax\n\n# 假设 unaries 是模型输出的概率图，形状为 (H, W, nlabels)\n# 例如：unaries = softmax_output_from_network\n\n# 转换为 CRF 所需的一元势能 (负对数概率) 并展平\n# 工具函数会自动处理 transpose 和 -log 操作\nU = unary_from_softmax(unaries)\nU = U.reshape((U.shape[0], -1))\n\n# 初始化 CRF: 宽，高，标签数量\nd = dcrf.DenseCRF2D(unaries.shape[1], unaries.shape[0], unaries.shape[2])\nd.setUnaryEnergy(U)\n```\n\n### 2. 添加成对势能 (Pairwise Potentials)\n添加两项常见的成对势能以平滑结果并保留边缘：\n1.  **颜色无关项 (Gaussian)**：仅基于像素位置。\n2.  **颜色相关项 (Bilateral)**：基于像素位置和颜色相似度。\n\n```python\n# im 为原始 RGB 图像数组，形状 (H, W, 3), dtype=uint8\nim = original_image \n\n# 添加高斯核 (位置平滑)\nd.addPairwiseGaussian(sxy=3, compat=3)\n\n# 添加双边核 (颜色保持边缘)\nd.addPairwiseBilateral(sxy=80, srgb=13, rgbim=im, compat=10)\n```\n\n### 3. 执行推理 (Inference)\n运行迭代推理并获取最终的分类结果。\n\n```python\n# 执行 5 次迭代推理\nQ = d.inference(5)\n\n# 获取最大后验概率 (MAP) 预测结果\n# Q 的形状为 (nlabels, H*W)，需取最大值索引并重塑回图像尺寸\nmap_prediction = np.argmax(Q, axis=0).reshape((unaries.shape[0], unaries.shape[1]))\n\n# 如果需要每个类别的概率分布，可转换为 numpy 数组\nprobabilities = np.array(Q)\n```","某医疗影像团队正在开发肺结节自动分割系统，利用深度学习模型生成的概率图往往边缘模糊，难以满足临床手术规划对精度的严苛要求。\n\n### 没有 pydensecrf 时\n- **边缘粗糙锯齿化**：仅依赖神经网络输出的分割掩码在结节边界处呈现明显的阶梯状锯齿，缺乏平滑度。\n- **细节丢失严重**：微小的毛刺征或分叶特征容易被模型的池化层抹平，导致早期病变特征识别不全。\n- **后处理逻辑复杂**：工程师需手动编写复杂的形态学操作（如开闭运算）或条件随机场代码来优化边缘，调试困难且运行缓慢。\n- **概率信息浪费**：直接使用硬分类结果（Hard Labeling），忽略了模型输出的软概率分布中蕴含的空间上下文信息。\n\n### 使用 pydensecrf 后\n- **亚像素级边缘优化**：通过 `DenseCRF2D` 结合高斯核与颜色势函数，自动将分割边界贴合到图像真实的梯度变化上，消除锯齿。\n- **精细结构保留**：利用全连接 CRF 的长程依赖能力，有效恢复了微小结节的毛刺和纹理细节，提升诊断可信度。\n- **集成高效便捷**：仅需几行 Python 代码即可调用底层 C++ 加速的推理引擎，无需重复造轮子，大幅缩短研发周期。\n- **概率分布精炼**：直接将 Softmax 输出的负对数概率作为一元势能输入，结合空间与外观特征进行全局能量最小化，显著提升分割准确度。\n\npydensecrf 通过将深度学习的语义理解能力与传统模型的空间约束能力完美结合，以极低的使用成本实现了医学影像分割精度的质的飞跃。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flucasb-eyer_pydensecrf_dcd2f5cd.png","lucasb-eyer","Lucas Beyer","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Flucasb-eyer_c8a3dfdc.jpg","Just some dude.","MSL Zürich (Ex: @openai @google Brain\u002FDeepMind)","\u003C3 Belgium, Switzerland","lucasb.eyer.be@gmail.com",null,"http:\u002F\u002Flucasb.eyer.be","https:\u002F\u002Fgithub.com\u002Flucasb-eyer",[86,90,94,98,101],{"name":87,"color":88,"percentage":89},"C++","#f34b7d",98,{"name":91,"color":92,"percentage":93},"C","#555555",1.3,{"name":95,"color":96,"percentage":97},"Python","#3572A5",0.3,{"name":99,"color":100,"percentage":97},"Cython","#fedf5b",{"name":102,"color":103,"percentage":104},"CMake","#DA3434",0.1,2013,425,"2026-04-02T08:33:08","MIT",4,"Linux, macOS, Windows","未说明",{"notes":113,"python":111,"dependencies":114},"该库基于 Cython 并需要编译 C++ 代码。在 Windows 上安装可能较复杂，建议通过 conda 安装或确保已正确安装 Cython 和 C++ 编译器。Ubuntu 14.04 自带的 Cython 版本过旧，建议使用虚拟环境安装最新版 Cython。在 Colab 或 Kaggle 环境中需先升级 Cython 再从 GitHub 源码安装。输入数据的数据类型必须为 float32，否则会报错。对于非 RGB 图像或多维数据，需使用通用方法手动构建成对势能。",[115,116,117],"Cython>=0.22","numpy","Eigen",[14,13],[120,121,122,123,124,125,126],"computer-vision","machine-learning","crf","pairwise-potentials","unary-potentials","cython","eigen","2026-03-27T02:49:30.150509","2026-04-06T05:44:18.038927",[130,135,140,145,150,154],{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},16390,"在 Windows 上安装 pydensecrf 失败怎么办？","Windows 用户直接使用 pip 安装可能会遇到编译错误。推荐的解决方案是使用 conda 从 conda-forge 频道安装：\n运行命令：conda install -c conda-forge pydensecrf\n如果必须使用 pip，请确保已安装对应 Python 版本和系统架构的预编译 wheel 文件，或者尝试切换开发环境（例如有用户反馈从 Anaconda 切换到 PyCharm 原生环境解决了问题）。","https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F69",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},16391,"安装成功后导入模块报错 'No module named pydensecrf.eigen' 如何解决？","这是一个已知的安装路径问题。解决方法是卸载后重新安装：\n1. 运行 pip uninstall pydensecrf 卸载当前版本。\n2. 按照 README 中的说明重新运行 pip install 进行安装。\n维护者已修复该问题，重新安装通常能解决模块找不到的错误。","https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F11",{"id":141,"question_zh":142,"answer_zh":143,"source_url":144},16392,"inference 方法输出的标签范围与输入不一致（例如从 0-94 变成了 1-2）怎么办？","这是因为示例代码中的 compute_unary 函数对标签做了假设处理。如果需要保持原始标签范围（例如 0 到 N）：\n1. 参考 skimage 库中 relabel_sequential 函数的文档，利用其返回值进行“反向变换”以恢复原始标签。\n2. 或者编写自定义的 unary 计算函数。\n3. 简单的临时处理方法是通过数组映射强制还原，例如：arr[arr == 4] = 3。","https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F13",{"id":146,"question_zh":147,"answer_zh":148,"source_url":149},16393,"如何在离线环境（如 Kaggle Notebook）中使用 pydensecrf？","在无法联网的环境中，不能直接使用 pip install git+... 命令。解决方法是：\n1. 在有网络的环境下下载该项目的源代码包或数据集。\n2. 将其上传到离线环境（如 Kaggle Dataset）。\n3. 在代码中使用 sys.path.append('github master pydensecrf 路径') 将库路径加入系统路径。\n注意：这种方法可能需要环境已预装好编译依赖（如 Cython），否则仍可能报错。","https:\u002F\u002Fgithub.com\u002Flucasb-eyer\u002Fpydensecrf\u002Fissues\u002F89",{"id":151,"question_zh":152,"answer_zh":153,"source_url":134},16394,"Windows 上使用 pip 安装时出现 Visual Studio \u002F Eigen 编译错误如何处理？","该错误通常是因为缺少合适的编译环境或依赖。对于 Windows 10\u002F11 用户：\n1. 首选方案：避免源码编译，直接使用 conda 安装：conda install -c conda-forge pydensecrf。\n2. 如果必须编译，请确保安装了与 Python 版本匹配的 Microsoft Visual C++ Build Tools，并且所有安装工具已更新。\n3. 检查错误日志，确认是否因 Eigen 头文件路径问题导致，必要时手动指定 include 路径。",{"id":155,"question_zh":156,"answer_zh":157,"source_url":144},16395,"示例代码中的 M 参数（类别数）应该如何设置？","M 代表图像中存在的实际类别数量。示例中设置 M=21 是为了匹配特定的 C++ 示例。\n如果你的图像标签范围是 0 到 94，理论上可能有 95 个类，但实际有效类别数可能更少。\n建议修改代码以自动计算图像中实际存在的唯一标签数量，而不是硬编码 M 值。如果计算出的映射范围异常（如只有 1 到 2），请检查 unary 能量的计算逻辑是否正确覆盖了所有类别。",[]]