Created
June 30, 2015 13:24
-
-
Save reisepass/83741e0bfce3d1c62b0c to your computer and use it in GitHub Desktop.
decodeFn extract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that thetaUnary are the unary potentials and thetaPairwise are the pairwise potentials which we are learning on the outside via the Weight vector