Skip to content

Instantly share code, notes, and snippets.

@reisepass
Created June 30, 2015 13:24
Show Gist options
  • Save reisepass/83741e0bfce3d1c62b0c to your computer and use it in GitHub Desktop.
Save reisepass/83741e0bfce3d1c62b0c to your computer and use it in GitHub Desktop.
decodeFn extract
class RegionVar(val score: Int) extends IntegerVariable(score)
object PixelDomain extends DiscreteDomain(numClasses)
class Pixel(i: Int) extends DiscreteVariable(i) { //i is just the initial value
def domain = PixelDomain
}
val labelParams = Array.fill(graph.size) { new Pixel(0) }
val nodePairsUsed: HashSet[(Int, Int)] = new HashSet[(Int, Int)]()
for (idx <- 0 until labelParams.length) {
model ++= new Factor1(labelParams(idx)) {
def score(k: Pixel#Value) = thetaUnary(idx, k.intValue)
}
if (!DISABLE_PAIRWISE) {
graph.getC(idx).foreach { neighbour =>
{
if (!nodePairsUsed.contains((idx, neighbour)) && !nodePairsUsed.contains((neighbour, idx))) { //This prevents adding neighbours twice
nodePairsUsed.add((idx, neighbour))
model ++= new Factor2(labelParams(idx), labelParams(neighbour)) {
def score(i: Pixel#Value, j: Pixel#Value) = thetaPairwise(i.intValue, j.intValue)
}
}
}
}
}
}
if(counter<1) println("nodePairsFound" +nodePairsUsed.size+" Input thetaUnary("+thetaUnary.rows+","+thetaUnary.cols+")/nFactor Graph Size: "+model.factors.size)//TODO remove
@reisepass
Copy link
Author

Note that thetaUnary are the unary potentials and thetaPairwise are the pairwise potentials which we are learning on the outside via the Weight vector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment