1 #include "InferDense.h" 2 #include "IEdgeModel.h" 8 void normalize(
const Mat &src, Mat dst) {
9 if(dst.empty()) dst = Mat(src.size(), src.type());
10 for (
int y = 0; y < src.rows; y++) {
11 const T *pSrc = src.ptr<T>(y);
12 T *pDst = dst.ptr<T>(y);
14 for (
int x = 0; x < src.cols; x++) sum += pSrc[x];
15 if (sum > DBL_EPSILON)
16 for (
int x = 0; x < src.cols; x++) pDst[x] = pSrc[x] / sum;
21 void myexp(
const Mat &src, Mat &dst)
23 for (
int y = 0; y < src.rows; y++) {
24 const T *pSrc = src.ptr<
float>(y);
25 T *pDst = dst.ptr<
float>(y);
29 for (
int x = 1; x < src.cols; x++)
30 if (pSrc[x] > max) max = pSrc[x];
32 for (
int x = 0; x < src.cols; x++)
33 pDst[x] = expf(pSrc[x] - max);
42 Mat nodePotentials0 = nodePotentials.clone();
43 Mat temp = Mat(nodePotentials.size(), nodePotentials.type());
47 for (
unsigned int i = 0; i < nIt; i++) {
48 #ifdef DEBUG_PRINT_INFO 49 if (i == 0) printf(
"\n");
50 if (i % 5 == 0) printf(
"--- It: %d ---\n", i);
52 normalize<float>(nodePotentials, nodePotentials);
57 edgePotModel->apply(nodePotentials, tmp);
58 multiply(temp, tmp, temp);
61 multiply(nodePotentials0, temp, nodePotentials);
Mat getNodePotentials(void) const
Returns the container with node potentials.
CGraphDense & getGraphDense(void) const
Returns the dense graph.
virtual void infer(unsigned int nIt=1)
Inference.