lucasb-eyer / pydensecrf

Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
MIT License
1.94k stars 416 forks source link

About the compat parameter #55

Closed siinem closed 6 years ago

siinem commented 6 years ago

Dear @lucasb-eyer I am trying to apply dense CRF postprocessing to semantically labeled images (which are computed by deep learning techniques). Reading the commits in this repository i saw that the compat parameter denotes the compatibility function mentioned in the paper which adopts the Potts model [ related commit: https://github.com/lucasb-eyer/pydensecrf/commit/a9d7be19fc1a149915a15f084e9936aec5a52cef ]

However, I donot understand what does it mean to assign a constant value to this parameter. For example at the code below, what does it mean compatibility function is assigned as 3:

    d.addPairwiseGaussian(sxy=(3,3), compat=3,
                          kernel=dcrf.DIAG_KERNEL, normalization=dcrf.NORMALIZE_SYMMETRIC)

   d.addPairwiseBilateral(sxy=(30,30), compat=10,
                               kernel=dcrf.DIAG_KERNEL, normalization=dcrf.NORMALIZE_SYMMETRIC,
                               srgb=(3,3,3), rgbim=img[0])

Does it mean that only 3-pixel neighborhoods are considered to penalize differently labeled pixels? Because the equation given at the paper is mu(x_i,x_j) = 1 if x_i != x_j and 0 otherwise. So where we include that constant value in this equation???

dimimal commented 6 years ago

I am interested about that too.

Toz3wm commented 6 years ago

From what I get looking at labelcompatibility.cpp, I would say that compat=3 will give you 3*identity_matrix as compatibility matrix. This is - if i'm not mistaken - the same as compat = 1 as the compatibility matrix is only a weighting matrix.

compat=1D-array would give you the ability to "weight" different classes differently (however I'm not sure about the relevance of such a thing). compat=2D-array allows you to set a specific weight to each possible mislabelation (as stated in doc, setting a higher cost for mistaking cat for sky than bird for sky).

lucasb-eyer commented 6 years ago

Late answer, but @Toz3wm is right. No need to look at the code, though, this is all described in the README.

I believe passing a 2D-array is most useful here if you actually want to use label-compatibility, though I am not aware of people using it myself. I'm closing this issue as I believe nothing is left unanswered (it's basically all in the README), but please feel free to re-open if I missed something!

lucasb-eyer commented 6 years ago

Oh, and if someone has a simple, small example where using a label-compatibility matrix improves result, I'd be happy to include it as an example!

louisabraham commented 5 years ago

I'm asking a related question at #97: is the scaling important when you have more than one energy?

For example, if you have compat=3 and compat=10, is it the same as compat=6 and compat=20?