Bjoern Froehlich 13 роки тому
батько
коміт
92c3c519cb
2 змінених файлів з 68 додано та 59 видалено
  1. 64 55
      semseg/SemSegContextTree.cpp
  2. 4 4
      semseg/SemSegContextTree.h

+ 64 - 55
semseg/SemSegContextTree.cpp

@@ -53,16 +53,11 @@ SemSegContextTree::SemSegContextTree ( const Config *conf, const MultiDataset *m
 
   string segmentationtype = conf->gS ( section, "segmentation_type", "meanshift" );
 
-  useGaussian = conf->gB ( section, "use_gaussian", true );
-
   randomTests = conf->gI ( section, "random_tests", 10 );
 
   bool saveLoadData = conf->gB ( "debug", "save_load_data", false );
   string fileLocation = conf->gS ( "debug", "datafile", "tmp.txt" );
 
-  if ( useGaussian )
-    throw ( "there something wrong with using gaussian! first fix it!" );
-
   pixelWiseLabeling = false;
 
   if ( segmentationtype == "meanshift" )
@@ -77,7 +72,7 @@ SemSegContextTree::SemSegContextTree ( const Config *conf, const MultiDataset *m
   else
     throw ( "no valid segmenation_type\n please choose between none, meanshift and felzenszwalb\n" );
 
-  ftypes = conf->gI ( section, "features", 2 );;
+  ftypes = conf->gI ( section, "features", 100 );;
 
   string featsec = "Features";
 
@@ -115,25 +110,6 @@ SemSegContextTree::SemSegContextTree ( const Config *conf, const MultiDataset *m
   useGradient = conf->gB ( featsec, "use_gradient", true );
   useRegionFeature = conf->gB ( featsec, "use_region", true );
   
-  
-  //define which featurextraction methods should be used for each channel
-#ifdef LOCALFEATS
-  int colorchannels = 9;
-#else
-  int colorchannels = 3;
-#endif
-  
-  if(useGradient)
-    colorchannels *= 2;
-  
-  for(int i = 0; i < colorchannels; i++)
-  {
-    channelType.push_back(0);
-  }
-  
-  if(useRegionFeature)
-    channelType.push_back(1);  
-
   opOverview = vector<int> ( NBOPERATIONS, 0 );
   contextOverview = vector<vector<double> > ( maxDepth, vector<double> ( 2, 0.0 ) );
 
@@ -205,8 +181,6 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
       fraction[i] = 0;
     else
       fraction[i] = ( ( double ) maxSamples ) / ( ( double ) featcounter * a[i] * a.size() );
-
-    //cout << "fraction["<<i<<"]: "<< fraction[i] << " a[" << i << "]: " << a[i] << endl;
   }
 
   featcounter = 0;
@@ -242,8 +216,6 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
       }
     }
   }
-  //cout << "size: " << selFeats.size() << endl;
-  //getchar();
 
   map<int, int>::iterator mapit;
 
@@ -251,7 +223,6 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
 
   for ( mapit = e.begin() ; mapit != e.end(); mapit++ )
   {
-    //cout << "class: " << mapit->first << ": " << mapit->second << endl;
     double p = ( double ) ( *mapit ).second / ( double ) featcounter;
     globent += p * log2 ( p );
   }
@@ -260,12 +231,9 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
 
   if ( globent < 0.5 )
   {
-    //cout << "globent to small: " << globent << endl;
     return 0.0;
   }
 
-  int classes = ( int ) forest[tree][0].dist.size();
-
   featsel.clear();
 
   for ( int i = 0; i < featsPerSplit; i++ )
@@ -283,21 +251,10 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
       tmpws *= 4;
     }
 
-    if ( useGaussian )
-    {
-      double sigma = ( double ) tmpws * 2.0;
-      x1 = randGaussDouble ( sigma ) * ( double ) tmpws;
-      x2 = randGaussDouble ( sigma ) * ( double ) tmpws;
-      y1 = randGaussDouble ( sigma ) * ( double ) tmpws;
-      y2 = randGaussDouble ( sigma ) * ( double ) tmpws;
-    }
-    else
-    {
-      x1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
-      x2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
-      y1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
-      y2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
-    }
+    x1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
+    x2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
+    y1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
+    y2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) tmpws ) - tmpws / 2;
 
     if ( ft == 0 )
     {
@@ -335,7 +292,7 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
         o -= opssize;
         op = cops[o]->clone();
         op->set ( x1, y1, x2, y2, f1, f2, calcVal[ft] );
-        if ( f1 < forest[0][0].dist.size() )
+        if ( f1 < (int)forest[0][0].dist.size() )
           op->setContext ( true );
         else
           op->setContext ( false );
@@ -724,6 +681,46 @@ void SemSegContextTree::train ( const MultiDataset *md )
     classes++;
   }
 
+////////////////////////////////////////////////////
+  //define which featurextraction methods should be used for each channel
+#ifdef LOCALFEATS
+  int colorchannels = 9;
+#else
+  int colorchannels = 3;
+#endif
+  
+  if(useGradient)
+    colorchannels *= 2;
+  
+  // gray value images 
+  for(int i = 0; i < colorchannels; i++)
+  {
+    channelType.push_back(0);
+  }
+  
+  // regions
+  if(useRegionFeature)
+    channelType.push_back(2);
+  
+  // integral images
+  for(int i = 0; i < colorchannels+classes; i++)
+  {
+    channelType.push_back(1);
+  }
+  
+  int amountTypes = 3;
+  
+  channelsPerType = vector<vector<int> >(amountTypes, vector<int>());
+  
+  for(int i = 0; i < channelType.size(); i++)
+  {
+    channelsPerType[channelType[i]].push_back(i);
+  }
+  
+  ftypes = std::min(amountTypes,ftypes);
+  
+////////////////////////////////////////////////////
+
   //balancing
   int featcounter = 0;
 
@@ -1021,13 +1018,8 @@ void SemSegContextTree::train ( const MultiDataset *md )
 #endif
     }
 
-    //compute integral image
+    //compute integral images
     int channels = classes + allfeats[0].channels();
-#if 0
-    timer.stop();
-    cout << "time for part0: " << timer.getLast() << endl;
-    timer.start();
-#endif
 
     if ( integralImgs[0].width() == 0 )
     {
@@ -1584,6 +1576,13 @@ void SemSegContextTree::store ( std::ostream & os, int format ) const
       }
     }
   }
+  
+  os << channelType.size() << endl;
+  for(int i = 0; i < channelType.size(); i++)
+  {
+    os << channelType[i] << " ";
+  }
+  os << endl;
 }
 
 void SemSegContextTree::restore ( std::istream & is, int format )
@@ -1670,6 +1669,16 @@ void SemSegContextTree::restore ( std::istream & is, int format )
       }
     }
   }
+  
+  channelType.clear();
+  int ctsize;
+  is >> ctsize;
+  for(int i = 0; i < ctsize; i++)
+  {
+    int tmp;
+    is >> tmp;
+    channelType.push_back(tmp);
+  }
 }
 
 

+ 4 - 4
semseg/SemSegContextTree.h

@@ -101,9 +101,6 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
     /** use pixelwise labeling or regionlabeling with additional segmenation */
     bool pixelWiseLabeling;
 
-    /** use Gaussian distributed features based on the feature position */
-    bool useGaussian;
-
     /** Number of trees used for the forest */
     int nbTrees;
     
@@ -114,7 +111,10 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
     bool useRegionFeature;
 
     /** how to handle each channel */
-    vector<int> channelType;
+    std::vector<int> channelType;
+    
+    /** list of channels per feature type */
+    std::vector<std::vector<int> > channelsPerType;
     
   public:
     /** simple constructor */