瀏覽代碼

rm progs/convertFeatures2.cpp

Bjoern Froehlich 13 年之前
父節點
當前提交
6cb4601745
共有 3 個文件被更改,包括 67 次插入136 次删除
  1. 0 92
      progs/convertFeatures2.cpp
  2. 52 44
      semseg/SemSegContextTree.cpp
  3. 15 0
      semseg/SemSegContextTree.h

+ 0 - 92
progs/convertFeatures2.cpp

@@ -1,92 +0,0 @@
-/**
-* @file testClassifier.cpp
-* @brief main program for classifier evaluation
-* @author Erik Rodner
-* @date 2007-10-12
-*/
-
-#include <fstream>
-#include <iostream>
-
-#include <vislearning/cbaselib/MultiDataset.h>
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
-#include <vislearning/cbaselib/ClassificationResults.h>
-#include <objrec/iclassifier/codebook/MutualInformation.h>
-
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include <vislearning/classifier/fpclassifier/randomforest/FPCRandomForestTransfer.h>
-#include <vislearning/classifier/classifierinterfaces/VCFeaturePool.h>
-
-#include "core/basics/Config.h"
-#include <vislearning/baselib/Preprocess.h>
-#include <core/basics/StringTools.h>
-
-#undef DEBUG
-
-using namespace OBJREC;
-
-using namespace NICE;
-
-using namespace std;
-
-int main( int argc, char **argv )
-{
-  std::set_terminate( __gnu_cxx::__verbose_terminate_handler );
-
-  Config conf( argc, argv );
-  string fn = conf.gS( "main", "input", "train.vec" );
-  int format = conf.gI( "main", "format", 0 );
-  string outfn = conf.gS( "main", "output", "out.vec" );
-  int dim = conf.gI( "main", "dim", 0 );
-
-  ifstream fin( fn.c_str(), ifstream::in );
-
-  LabeledSetVector test;
-  vector<double> maxv( dim, numeric_limits<double>::min() );
-  vector<double> minv( dim, numeric_limits<double>::max() );
-
-  while ( fin.good() )
-  {
-    Vector tmp( dim );
-
-    for ( int i = 0; i < dim; i++ )
-    {
-      fin >> tmp[i];
-      maxv[i] = std::max( maxv[i], tmp[i] );
-      minv[i] = std::min( minv[i], tmp[i] );
-    }
-
-    int label;
-
-    fin >> label;
-    label--;
-
-    if ( label > 5 )
-      label--;
-
-    test.add( label, tmp );
-  }
-
-  for ( int i = 0; i < dim; i++ )
-  {
-    maxv[i] -= minv[i];
-  }
-
-  for ( map< int, vector<NICE::Vector *> >::iterator iter = test.begin(); iter != test.end(); ++iter )
-  {
-    for ( int j = 0; j < iter->second.size(); j++ )
-    {
-      for ( int i = 0; i < iter->second[j]->size(); i++ )
-      {
-        ( *( iter->second[j] ) )[i] = (( *( iter->second[j] ) )[i] - minv[i] ) / maxv[i];
-      }
-    }
-  }
-
-  test.save( outfn );
-
-  fin.close();
-
-
-  return 0;
-}

+ 52 - 44
semseg/SemSegContextTree.cpp

@@ -692,24 +692,42 @@ SemSegContextTree::SemSegContextTree ( const Config *conf, const MultiDataset *m
 
   ftypes = conf->gI ( section, "features", 2 );;
 
-  ops.push_back ( new Minus() );
-  ops.push_back ( new MinusAbs() );
-  ops.push_back ( new Addition() );
-  ops.push_back ( new Only1() );
-  ops.push_back ( new RelativeXPosition() );
-  ops.push_back ( new RelativeYPosition() );
-
-  cops.push_back ( new BiIntegralCenteredOps() );
-  cops.push_back ( new IntegralCenteredOps() );
-  cops.push_back ( new IntegralOps() );
-  cops.push_back ( new HaarHorizontal() );
-  cops.push_back ( new HaarVertical() );
-  cops.push_back ( new HaarDiag() );
-  cops.push_back ( new Haar3Horiz() );
-  cops.push_back ( new Haar3Vert() );
-  //cops.push_back( new GlobalFeats() );
+  string featsec = "Features";
+  
+  if(conf->gB ( featsec, "minus", true ))
+    ops.push_back ( new Minus() );
+  if(conf->gB ( featsec, "minus_abs", true ))
+    ops.push_back ( new MinusAbs() );
+  if(conf->gB ( featsec, "addition", true ))
+    ops.push_back ( new Addition() );
+  if(conf->gB ( featsec, "only1", true ))
+    ops.push_back ( new Only1() );
+  if(conf->gB ( featsec, "rel_x", true ))
+    ops.push_back ( new RelativeXPosition() );
+  if(conf->gB ( featsec, "rel_y", true ))
+    ops.push_back ( new RelativeYPosition() );
+
+  if(conf->gB ( featsec, "bi_int_cent", true ))
+    cops.push_back ( new BiIntegralCenteredOps() );
+  if(conf->gB ( featsec, "int_cent", true ))
+    cops.push_back ( new IntegralCenteredOps() );
+  if(conf->gB ( featsec, "int", true ))
+    cops.push_back ( new IntegralOps() );
+  if(conf->gB ( featsec, "haar_horz", true ))
+    cops.push_back ( new HaarHorizontal() );
+  if(conf->gB ( featsec, "haar_vert", true ))
+    cops.push_back ( new HaarVertical() );
+  if(conf->gB ( featsec, "haar_diag", true ))
+    cops.push_back ( new HaarDiag() );
+  if(conf->gB ( featsec, "haar3_horz", true ))
+    cops.push_back ( new Haar3Horiz() );
+  if(conf->gB ( featsec, "haar3_vert", true ))
+    cops.push_back ( new Haar3Vert() );
+  if(conf->gB ( featsec, "glob", true ))
+    cops.push_back( new GlobalFeats() );
 
   opOverview = vector<int> ( NBOPERATIONS, 0 );
+  contextOverview = vector<vector<double> >(maxDepth, vector<double>(2,0.0));
 
   calcVal.push_back ( new MCImageAccess() );
   calcVal.push_back ( new ClassificationResultAcess() );
@@ -877,6 +895,7 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
       int o = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) ops.size() );
       Operation *op = ops[o]->clone();
       op->set ( x1, y1, x2, y2, f1, f2, calcVal[ft] );
+      op->setContext(false);
       featsel.push_back ( op );
     }
     else if ( ft == 1 )
@@ -895,15 +914,21 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
         int f2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) chans );
         op = ops[o]->clone();
         op->set ( x1, y1, x2, y2, f1, f2, calcVal[ft] );
+        op->setContext(true);
       }
       else
       {
         int chans = integralImgs[0].channels();
         int f1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) chans );
         int f2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) chans );
+        
         o -= opssize;
         op = cops[o]->clone();
         op->set ( x1, y1, x2, y2, f1, f2, calcVal[ft] );
+        if(f1 < forest[0][0].dist.size())
+          op->setContext(true);
+        else
+          op->setContext(false);
       }
 
       featsel.push_back ( op );
@@ -1153,34 +1178,6 @@ void SemSegContextTree::train ( const MultiDataset *md )
 
   int imgcounter = 0;
 
-  /*
-  MultiChannelImageT<int> ttmp2(0,0,0);
-  MultiChannelImageT<double> ttmp1(100,100,1);
-  MultiChannelImageT<double> tint(100,100,1);
-  ttmp1.setAll(1.0);
-  tint.setAll(0.0);
-  computeIntegralImage(ttmp2,ttmp1,tint);
-
-
-  for(int i = 0; i < cops.size(); i++)
-  {
-   Features feats;
-   feats.feats = &tint;
-   feats.cfeats = &ttmp2;
-   feats.cTree = 0;
-   feats.tree = new vector<TreeNode>;
-   feats.integralImg = &tint;
-   cops[i]->set(-10, -6, 8, 9, 0, 0, new MCImageAccess());
-   cout << "for: " << cops[i]->writeInfos() << endl;
-   int y = 50;
-   for(int x = 40; x < 44; x++)
-   {
-    cout << "x: " << x << " val: " << cops[i]->getVal(feats, x, y) << endl;
-   }
-  }
-
-  getchar();*/
-
   int amountPixels = 0;
 
   LOOP_ALL_S ( *trainp )
@@ -1588,6 +1585,7 @@ void SemSegContextTree::train ( const MultiDataset *md )
       {
         cout <<  ", feat: " << forest[tree][i].feat->writeInfos() << " ";
         opOverview[forest[tree][i].feat->getOps() ]++;
+        contextOverview[depth][forest[tree][i].feat->getContext()]++;
       }
 
       for ( int d = 0; d < ( int ) forest[tree][i].dist.size(); d++ )
@@ -1608,6 +1606,16 @@ void SemSegContextTree::train ( const MultiDataset *md )
   {
     cout << cops[c]->writeInfos() << ": " << opOverview[cops[c]->getOps() ] << endl;
   }
+  
+  for(int d = 0; d < maxDepth; d++)
+  {
+    double sum =  contextOverview[d][0] + contextOverview[d][1];
+    
+    contextOverview[d][0] /= sum;
+    contextOverview[d][1] /= sum;
+    
+    cout << "depth: " << d << " woContext: " << contextOverview[d][0] << " wContext: " << contextOverview[d][0] << endl;
+  }
 
 #endif
 }

+ 15 - 0
semseg/SemSegContextTree.h

@@ -103,6 +103,8 @@ class Operation
   protected:
     int x1, y1, x2, y2, channel1, channel2;
     ValueAccess *values;
+    
+    bool context;
 
   public:
 
@@ -121,6 +123,16 @@ class Operation
       channel2 = _channel2;
       values = _values;
     }
+    
+    void setContext(bool _context)
+    {
+      context = _context;
+    }
+    
+    bool getContext()
+    {
+      return context;
+    }
 
     /**
      * @brief abstract interface for feature computation
@@ -197,6 +209,9 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
 
     /** counter for used operations */
     std::vector<int> opOverview;
+    
+    /** relative use of context vs raw features per tree level*/
+    vector<vector<double> > contextOverview;
 
     /** the minimum number of features allowed in a leaf */
     int minFeats;