Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
| Date | Stars |
|---|---|
| 2026-07-24 | 2023 |
| 2026-07-25 | 2022 |
| 2026-07-28 | 2022 |
| 2026-07-30 | 2022 |
| 2026-08-06 | 2022 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
PyDenseCRF
==========
This is a (Cython-based) Python wrapper for [Philipp Krähenbühl's Fully-Connected CRFs](http://web.archive.org/web/20161023180357/http://www.philkr.net/home/densecrf) (version 2, [new, incomplete page](http://www.philkr.net/2011/12/01/nips/)).
If you use this code for your reasearch, please cite:
```
Efficient Inference in Fully Connected CRFs with Gaussian Edge Potentials
Philipp Krähenbühl and Vladlen Koltun
NIPS 2011
```
and provide a link to this repository as a footnote or a citation.
Installation
============
The package is on PyPI, so simply run `pip install pydensecrf` to install it.
If you want the newest and freshest version, you can install it by executing:
```
pip install git+https://github.com/lucasb-eyer/pydensecrf.git
```
and ignoring all the warnings coming from Eigen.
Note that you need a relatively recent version of Cython (at least version 0.22) for this wrapper,
the one shipped with Ubuntu 14.04 is too old. (Thanks to Scott Wehrwein for pointing this out.)
I suggest you use a [virtual environment](https://virtualenv.readthedocs.org/en/latest/) and install
the newest version of Cython there (`pip install cython`), but you may update the system version by
```
sudo apt-get remove cython
sudo pip install -U cython
```
### Problems on Windows/VS
Since this library needs to compile C++ code, installation can be a little more problematic than pure Python packages.
Make sure to [have Cython installed](https://github.com/lucasb-eyer/pydensecrf/issues/62#issuecomment-400563257) or try [installing via conda instead](https://github.com/lucasb-eyer/pydensecrf/issues/69#issuecomment-400639881) if you are getting problems.
PRs that improve Windows support are welcome.
### Problems on Colab/Kaggle Kernel
`pydensecrf` does not come pre-installed in Colab or Kaggle Kernel. Running `pip install pydensecrf` will result into
build failures. Follow these steps instead for Colab/Kaggle Kernel:
```
pip install -U cython
pip install git+https://github.com/lucasb-eyer/pydensecrf.git
```
Usage
=====
For images, the easiest way to use this library is using the `DenseCRF2D` class:
```python
import numpy as np
import pydensecrf.densecrf as dcrf
d = dcrf.DenseCRF2D(640, 480, 5) # width, height, nlabels
```
Unary potential
---------------
You can then set a fixed unary potential in the following way:
```python
U = np.array(...) # Get the unary in some way.
print(U.shape) # -> (5, 480, 640)
print(U.dtype) # -> dtype('float32')
U = U.reshape((5,-1)) # Needs to be flat.
d.setUnaryEnergy(U)
# Or alternatively: d.setUnary(ConstUnary(U))
```
Remember that `U` should be negative log-probabilities, so if you're using
probabilities `py`, don't forget to `U = -np.log(py)` them.
Requiring the `reshape` on the unary is an API wart that I'd like to fix, but
don't know how to without introducing an explicit dependency on numpy.
**Note** that the `nlabels` dimension is the first here before the reshape;
you may need to move it there before reshaping if that's not already the case,
like so:
```python
print(U.shape) # -> (480, 640, 5)
U = U.transpose(2, 0, 1).reshape((5,-1))
```
### Getting a Unary
There's two common ways of getting unary potentials:
1. From a hard labeling generated by a human or some other processing.
This case is covered by `from pydensecrf.utils import unary_from_labels`.
2. From a probability distribution computed by, e.g. the softmax output of a
deep network. For this, see `from pydensecrf.utils import unary_from_softmax`.
For usage of both of these, please refer to their docstrings or have a look at [the example](examples/inference.py).
Pairwise potentials
-------------------
The two-dimensional case has two utility methods for adding the most-common pairwise potentials:
```python
# This adds the color-independent term, features are the locations only.
d.addPairwiseGaussian(sxy=(3,3), compat=3, kernel=dcrf.DIAG_KERNEL, normalization=dcrf.NORMALIZE_SExcerpt of 12,325 characters
Read on GitHub67
Marvin Teichmann · University of Cambridge · United Kingdom
7
3
2
1
1
1
1
Sayak Paul · @huggingface · India
1
1
Jiahao Li · @bytedance · China
1
1
Alexander Lyzhov
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:d8b16acbf5cd25d8, topic:computer-vision