Эх сурвалжийг харах

Merge branch 'master' of dbv.inf-cv.uni-jena.de:nice/nice-semseg

Alexander Freytag 9 жил өмнө
parent
commit
2f2d9e7514

+ 7 - 7
progs/testSemanticSegmentation3D.cpp

@@ -39,11 +39,11 @@ void startClassification (SemanticSegmentation *semseg,
                           const ClassNames & classNames,
                           const set<int> & forbidden_classes,
                           std::map<int,int> & classMapping,
-                          const bool doCrossVal)
+                          const unsigned short cvRuns)
 {
     bool write_results = conf.gB ( "debug", "write_results", false );
     bool writeProbMaps = conf.gB ( "debug", "write_prob_maps", false );
-    if (doCrossVal)
+    if (cvRuns > 1)
         write_results = false;
 
     bool run_3Dseg = conf.gB( "SSContextTree", "run_3dseg", false);
@@ -181,7 +181,7 @@ int main ( int argc, char **argv )
     ResourceStatistics rs;
 
     /*---------------CONFIGURATION---------------*/
-    bool doCrossVal = conf.gB ( "debug", "do_crossval", false );
+    unsigned short crossValRuns = conf.gI ( "debug", "cross_val_runs", 1 );
     /*-------------------------------------------*/
 
 #ifdef DEBUG
@@ -219,7 +219,7 @@ int main ( int argc, char **argv )
     SemanticSegmentation *semseg = NULL;
 
     // TRAINING AND TESTING
-    if (!doCrossVal)
+    if ( crossValRuns == 1 )
     {
         semseg = new SemSegContextTree3D ( &conf, &classNames );
 
@@ -232,14 +232,14 @@ int main ( int argc, char **argv )
         cout << "##############\n" << endl;
         const LabeledSet *testFiles = md["test"];
         startClassification (semseg, M_vec, conf, testFiles, classNames,
-                             forbidden_classes, classMapping, doCrossVal );
+                             forbidden_classes, classMapping, crossValRuns );
 
         delete semseg;
     }
     else
     {
         // CROSS-VALIDATION
-        for (int cval = 1; cval <= 10; cval++)
+        for (int cval = 1; cval <= crossValRuns; cval++)
         {
             semseg = new SemSegContextTree3D ( &conf, &classNames );
 
@@ -257,7 +257,7 @@ int main ( int argc, char **argv )
             cout << "#################\n" << endl;
             const LabeledSet *testFiles = md[cvaltest];
             startClassification (semseg, M_vec, conf, testFiles, classNames,
-                                 forbidden_classes, classMapping, doCrossVal );
+                                 forbidden_classes, classMapping, crossValRuns );
 
             delete semseg;
         }

+ 3 - 2
semseg/SemSegContextTree3D.cpp

@@ -1250,15 +1250,16 @@ void SemSegContextTree3D::train ( const LabeledSet * trainp )
 
             if ( !forest[tree][node].isleaf && forest[tree][node].left != -1 )
             {
+#ifdef DEBUG
                 cout <<  forest[tree][node].feat->writeInfos() << endl;
+#endif
                 opOverview[ forest[tree][node].feat->getOps() ]++;
                 contextOverview[forest[tree][node].depth][ ( int ) forest[tree][node].feat->getContext() ]++;
             }
 #ifdef DEBUG
             for ( int d = 0; d < ( int ) forest[tree][node].dist.size(); d++ )
-            {
                 cout << " " << forest[tree][node].dist[d];
-            }
+
             cout << endl;
 #endif
         }

+ 25 - 15
semseg/SemSegTools.cpp

@@ -109,22 +109,28 @@ void SemSegTools::computeClassificationStatistics(
 
     overallTrue /= sumAll;
 
-    double truePos = (double)confMat(1,1);
-    //double trueNeg = (double)confMat(0,0);
-    double falsePos = (double)confMat(0,1);
-    double falseNeg = (double)confMat(1,0);
+    double precision = 0.0, recall = 0.0, f1score = 0.0, iuScore = 0.0;
 
-    // binary classification metrics
-    if ( classMappingInv.size() == 2 )
+    // binary classification
+    for ( int c = 0; c < classMappingInv.size(); c++ )
     {
-        double precision = truePos / (truePos+falsePos);
-        double recall = truePos / (truePos+falseNeg);
-        double f1score = 2.0*(precision*recall)/(precision+recall);
-        std::cout << "Precision: " << precision;
-        std::cout << "\nRecall: " << recall;
-        std::cout << "\nF1Score: " << f1score << "\n\n";
+        double precBase = 0.0, recBase = 0.0;
+        for ( int r = 0; r < classMappingInv.size(); r++ )
+            precBase += confMat(r,c);
+
+        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));
     }
 
+    precision /= classMappingInv.size();
+    recall /= classMappingInv.size();
+    iuScore /= classMappingInv.size();
+    f1score = 2.0*(precision*recall)/(precision+recall);
+
     // normalizing confMat using rows
     for ( int r = 0 ; r < (int) confMat.rows() ; r++ )
     {
@@ -170,9 +176,13 @@ void SemSegTools::computeClassificationStatistics(
     }
 
     // print classification statistics
-    std::cout << "\nOverall Recognition Rate: " << overallTrue;
-    std::cout << "\nAverage Recognition Rate: " << confMat.trace() / (double)classMappingInv.size();
-    std::cout << "\nLower Bound: " << 1.0 /(double)classMappingInv.size();
+    std::cout << "\nAccuracy: " << overallTrue;
+    std::cout << "\nPrecision: " << precision;
+    std::cout << "\nRecall: " << recall;
+    std::cout << "\nF1Score: " << f1score;
+    std::cout << "\nIU: " << iuScore;
+    std::cout << "\n\nAverage Recognition Rate: " << confMat.trace() / (double)classMappingInv.size();
+    //std::cout << "\nLower Bound: " << 1.0 /(double)classMappingInv.size();
     std::cout << std::endl;
 }