Forráskód Böngészése

revised performance statistics

Sven Sickert 8 éve
szülő
commit
5b88c97373
1 módosított fájl, 33 hozzáadás és 16 törlés
  1. 33 16
      semseg/SemSegTools.cpp

+ 33 - 16
semseg/SemSegTools.cpp

@@ -100,7 +100,7 @@ void SemSegTools::computeClassificationStatistics(
     std::cout << "\nPERFORMANCE" << std::endl;
     std::cout << "###########\n" << std::endl;
 
-    double overallTrue = confMat.trace();
+    double accuracy = confMat.trace();
     double sumAll  = 0.0;
 
     // overall recognition rate
@@ -108,31 +108,48 @@ void SemSegTools::computeClassificationStatistics(
         for ( int c = 0; c < (int) confMat.cols(); c++ )
             sumAll += confMat( r, c );
 
-    overallTrue /= sumAll;
+    accuracy /= sumAll;
 
-    double precision = 0.0, recall = 0.0, f1score = 0.0, iuScore = 0.0;
+    double prec = 0.0, rec = 0.0, f1score = 0.0, iuScore = 0.0;
 
-    // binary classification
+    // classification
+    int normConst = classMappingInv.size();
     for ( int c = 0; c < classMappingInv.size(); c++ )
     {
+        std::cout << "Class " << classNames.text( classMappingInv[c] ) << ":" << std::endl;
+        
         double precBase = 0.0, recBase = 0.0;
+        // row-wise sum
         for ( int r = 0; r < classMappingInv.size(); r++ )
             precBase += confMat(r,c);
 
+        // column-wise sum
         for ( int cc = 0; cc < classMappingInv.size(); cc++ )
             recBase += confMat(c,cc);
 
-        precision += confMat(c,c) / precBase;
-        recall += confMat(c,c) / recBase;
-        iuScore += confMat(c,c) / (precBase+recBase-confMat(c,c));
+        double precClass = 0, recClass = 0;
+        
+        if (precBase > 0) precClass = confMat(c,c) / precBase;
+
+        if (recBase > 0) recClass = confMat(c,c) / recBase;
+
+        std::cout << "  Precision: " << precClass << std::endl;
+        std::cout << "  Recall:    " << recClass << std::endl;
+        prec += precClass;
+        rec += recClass;
+
+        if (precBase > 0 && recBase > 0)
+            iuScore += confMat(c,c) / (precBase+recBase-confMat(c,c));
+        else
+            normConst--;
     }
 
-    precision /= classMappingInv.size();
-    recall /= classMappingInv.size();
-    iuScore /= classMappingInv.size();
-    f1score = 2.0*(precision*recall)/(precision+recall);
+    prec /= (double)normConst;
+    rec /= (double)normConst;
+    iuScore /= (double)normConst;
+    f1score = 2.0*(prec*rec)/(prec+rec);
 
-    // normalizing confMat using rows
+    // row-wise normalization of confMat
     for ( int r = 0 ; r < (int) confMat.rows() ; r++ )
     {
         double sum = 0.0;
@@ -177,12 +194,12 @@ void SemSegTools::computeClassificationStatistics(
     }
 
     // print classification statistics
-    std::cout << "\nAccuracy: " << overallTrue;
-    std::cout << "\nPrecision: " << precision;
-    std::cout << "\nRecall: " << recall;
+    std::cout << "\nAccuracy: " << accuracy;
+    std::cout << "\nPrecision: " << prec;
+    std::cout << "\nRecall: " << rec;
     std::cout << "\nF1Score: " << f1score;
     std::cout << "\nIU: " << iuScore;
-    std::cout << "\n\nAverage Recognition Rate: " << confMat.trace() / (double)classMappingInv.size();
+    //std::cout << "\n\nAverage Recognition Rate: " << confMat.trace() / (double)classMappingInv.size();
     //std::cout << "\nLower Bound: " << 1.0 /(double)classMappingInv.size();
     std::cout << std::endl;
 }