Bjoern Froehlich 13 ani în urmă
părinte
comite
a2b641bed9

+ 5 - 0
progs/testSemanticSegmentation.cpp

@@ -18,6 +18,7 @@
 #include <objrec-froehlichexp/semseg/SemanticSegmentation.h>
 #include <objrec-froehlichexp/semseg/SemSegLocal.h>
 #include <objrec-froehlichexp/semseg/SemSegCsurka.h>
+#include <objrec-froehlichexp/semseg/SemSegNovelty.h>
 #include <objrec-froehlichexp/semseg/SemSegRegionBased.h>
 #include <objrec-froehlichexp/semseg/SemSegContextTree.h>
 
@@ -102,6 +103,10 @@ int main( int argc, char **argv )
   {
     semseg = new SemSegContextTree( &conf, &md );
   }
+  else if( method == "SSNovelty" )
+  {
+    semseg = new SemSegNovelty( &conf, &md );
+  }
 
   //SemanticSegmentation *semseg = new SemSegLocal ( &conf, &md );
   //SemanticSegmentation *semseg = new SemSegSTF ( &conf, &md );

+ 32 - 16
semseg/SemSegContextTree.cpp

@@ -24,6 +24,8 @@
 #undef WRITEGLOB
 #undef TEXTONMAP
 
+#undef DEBUG
+
 //#define LOCALFEATS
 
 using namespace OBJREC;
@@ -276,8 +278,9 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
   {
     return 0.0;
   }
-
-  featsel.clear();
+  
+  /** vector of all possible features */
+  std::vector<Operation*> featsel;
 
   for ( int i = 0; i < featsPerSplit; i++ )
   {
@@ -305,9 +308,9 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
     y1 = (int)( (double)rand() / (double)RAND_MAX * (double)tmpws ) - tmpws / 2;
     y2 = (int)( (double)rand() / (double)RAND_MAX * (double)tmpws ) - tmpws / 2;
 
-    int f1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) channelsPerType[ft].size() );
-    int f2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) channelsPerType[ft].size() );
-    int o = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) ops[ft].size() );
+    int f1 = ( int ) ( (double) rand() / (double) RAND_MAX * (double) channelsPerType[ft].size() );
+    int f2 = ( int ) ( (double) rand() / (double) RAND_MAX * (double) channelsPerType[ft].size() );
+    int o = ( int ) ( (double) rand() / (double) RAND_MAX * (double) ops[ft].size() );
 
     Operation *op = ops[ft][o]->clone();
 
@@ -445,7 +448,7 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
   }*/
 
 
-#ifdef debug
+#ifdef DEBUG
   cout << "globent: " << globent <<  " bestig " << bestig << " splitval: " << splitval << endl;
 
 #endif
@@ -587,6 +590,8 @@ inline double computeWeight ( const double &d, const double &dim )
 
 void SemSegContextTree::train ( const MultiDataset *md )
 {
+  Timer timer;
+  timer.start();
   const LabeledSet train = * ( *md ) ["train"];
   const LabeledSet *trainp = &train;
 
@@ -710,7 +715,7 @@ void SemSegContextTree::train ( const MultiDataset *md )
 ////////////////////////////////////////////////////
   //define which featurextraction methods should be used for each channel
 #ifdef LOCALFEATS
-  rawChannels = 9;
+  rawChannels = 11;
 #else
   rawChannels = 3;
 #endif
@@ -832,6 +837,10 @@ void SemSegContextTree::train ( const MultiDataset *md )
   bool allleaf = false;
   //int baseFeatSize = allfeats[0].size();
 
+  timer.stop();
+  cerr << "preprocessing finished in: " << timer.getLastAbsolute() << " seconds" << endl;
+  timer.start();
+  
   while ( !allleaf && depth < maxDepth )
   {
     depth++;
@@ -842,8 +851,8 @@ void SemSegContextTree::train ( const MultiDataset *md )
     vector<MultiChannelImageT<unsigned short int> > lastfeats = currentfeats;
 
 #if 1
-    Timer timer;
-    timer.start();
+    Timer timerDepth;
+    timerDepth.start();
 #endif
 
     double weight = computeWeight ( depth, maxDepth ) - computeWeight ( depth - 1, maxDepth );
@@ -853,20 +862,20 @@ void SemSegContextTree::train ( const MultiDataset *md )
       weight = computeWeight ( 1, maxDepth );
     }
 
+#pragma omp parallel for
     for ( int tree = 0; tree < nbTrees; tree++ )
     {
       int t = (int)forest[tree].size();
       int s = startnode[tree];
       startnode[tree] = t;
-      //TODO vielleicht parallel wenn nächste schleife trotzdem noch parallelsiert würde, die hat mehr gewicht
-      //#pragma omp parallel for
+#pragma omp parallel for
       for ( int i = s; i < t; i++ )
       {
         if ( !forest[tree][i].isleaf && forest[tree][i].left < 0 )
         {
           Operation *splitfeat = NULL;
           double splitval;
-          double bestig = getBestSplit ( allfeats, lastfeats, labels, i, splitfeat, splitval, tree );
+          double bestig = getBestSplit(allfeats, lastfeats, labels, i, splitfeat, splitval, tree);
 
           for ( int ii = 0; ii < lastfeats.size(); ii++ )
           {
@@ -1047,11 +1056,15 @@ void SemSegContextTree::train ( const MultiDataset *md )
     }
 
 #if 1
-    timer.stop();
+    timerDepth.stop();
 
-    cout << "time for depth " << depth << ": " << timer.getLast() << endl;
+    cout << "time for depth " << depth << ": " << timerDepth.getLastAbsolute() << endl;
 #endif
   }
+  
+  timer.stop();
+  cerr << "learning finished in: " << timer.getLastAbsolute() << " seconds" << endl;
+  timer.start();
 
 #ifdef WRITEGLOB
   ofstream outstream ( "globtrain.feat" );
@@ -1128,8 +1141,11 @@ void SemSegContextTree::train ( const MultiDataset *md )
 
     cout << "depth: " << d << " woContext: " << contextOverview[d][0] << " wContext: " << contextOverview[d][1] << endl;
   }
-
 #endif
+
+  timer.stop();
+  cerr << "rest finished in: " << timer.getLastAbsolute() << " seconds" << endl;
+  timer.start();
 }
 
 void SemSegContextTree::extractBasicFeatures ( NICE::MultiChannelImageT<double> &feats, const ColorImage &img, const string &currentFile )
@@ -1214,7 +1230,7 @@ void SemSegContextTree::extractBasicFeatures ( NICE::MultiChannelImageT<double>
         // copy standard image to double image
         for ( uint y = 0 ; y < confidenceImage.height(); y++ )
           for ( uint x = 0 ; x < confidenceImage.width(); x++ )
-            feats ( x, y, currentChannel ) = ( double ) confidenceImage ( x, y );
+            feats ( x, y, currentChannel ) = (double) confidenceImage ( x, y );
       }
     }
   }

+ 0 - 3
semseg/SemSegContextTree.h

@@ -80,9 +80,6 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
 
     std::vector<ValueAccess*> calcVal;
 
-    /** vector of all possible features */
-    std::vector<Operation*> featsel;
-
     /** use alternative calculation for information gain */
     bool useShannonEntropy;