Bjoern Froehlich 13 năm trước cách đây
mục cha
commit
4da7b9c845
4 tập tin đã thay đổi với 631 bổ sung615 xóa
  1. 403 400
      semseg/SemSegContextTree.cpp
  2. 13 1
      semseg/SemSegContextTree.h
  3. 170 169
      semseg/SemSegSTF.cpp
  4. 45 45
      semseg/SemSegSTF.h

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 403 - 400
semseg/SemSegContextTree.cpp


+ 13 - 1
semseg/SemSegContextTree.h

@@ -44,6 +44,9 @@ class TreeNode
 
     /** how many pixels are in this node */
     int featcounter;
+    
+    /** unique number */
+    int nodeNumber;
 
     /** simple constructor */
     TreeNode() : left ( -1 ), right ( -1 ), feat ( NULL ), decision ( -1.0 ), isleaf ( false ) {}
@@ -145,7 +148,7 @@ class Operation
      **/
     virtual double getVal ( const Features &feats, const int &x, const int &y ) = 0;
     virtual Operation* clone() = 0;
-    virtual std::string writeInfos() = 0;
+    virtual std::string writeInfos();
 
     inline void getXY ( const Features &feats, int &xsize, int &ysize )
     {
@@ -287,6 +290,15 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @return void
      **/
     void computeIntegralImage ( const NICE::MultiChannelImageT<unsigned short int> &currentfeats, const NICE::MultiChannelImageT<double> &lfeats, NICE::MultiChannelImageT<double> &integralImage );
+    
+    /**
+     * @brief computes integral image for Sparse Multichannel Image
+     *
+     * @param currentfeats input features
+     * @param integralImage output image (must be initilized)
+     * @return void
+     **/
+    void computeIntegralImage ( const NICE::MultiChannelImageT<SparseVector> &infeats, NICE::MultiChannelImageT<SparseVector> &integralImage );
 
     /**
      * compute best split for current settings

+ 170 - 169
semseg/SemSegSTF.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file SemSegSTF.cpp
 * @brief Localization system
 * @author Erik Rodner
@@ -30,110 +30,110 @@ using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-SemSegSTF::SemSegSTF( const Config *conf, 
-		    const MultiDataset *md )
-    : SemanticSegmentation ( conf, &(md->getClassNames("train")) )
+SemSegSTF::SemSegSTF ( const Config *conf,
+                       const MultiDataset *md )
+    : SemanticSegmentation ( conf, & ( md->getClassNames ( "train" ) ) )
 {
-    use_semantic_features = conf->gB("bost", "use_semantic_features", true );
-    use_pixelpair_features = conf->gB("bost", "use_pixelpair_features", true );
-    subsamplex = conf->gI("bost", "subsamplex", 5);
-    subsampley = conf->gI("bost", "subsampley", 5);
-    numClasses = md->getClassNames("train").numClasses();
-
-    read_pixel_cache = conf->gB("FPCPixel", "read_cache", false );
-    cachepixel = conf->gS("FPCPixel", "cache", "fpc.data" );
-
-    read_seg_cache = conf->gB("FPCSeg", "read_cache", true );
-    cacheseg = conf->gS("FPCSeg", "cache", "segforest.data" );
-
-    Examples examples;
-    vector<CachedExample *> imgexamples;
-
-    fpcPixel = new FPCRandomForests ( conf, "FPCPixel" );
-    fpcPixel->setMaxClassNo ( classNames->getMaxClassno() );
-    if ( !read_pixel_cache || !read_seg_cache ) 
+  use_semantic_features = conf->gB ( "bost", "use_semantic_features", true );
+  use_pixelpair_features = conf->gB ( "bost", "use_pixelpair_features", true );
+  subsamplex = conf->gI ( "bost", "subsamplex", 5 );
+  subsampley = conf->gI ( "bost", "subsampley", 5 );
+  numClasses = md->getClassNames ( "train" ).numClasses();
+
+  read_pixel_cache = conf->gB ( "FPCPixel", "read_cache", false );
+  cachepixel = conf->gS ( "FPCPixel", "cache", "fpc.data" );
+
+  read_seg_cache = conf->gB ( "FPCSeg", "read_cache", true );
+  cacheseg = conf->gS ( "FPCSeg", "cache", "segforest.data" );
+
+  Examples examples;
+  vector<CachedExample *> imgexamples;
+
+  fpcPixel = new FPCRandomForests ( conf, "FPCPixel" );
+  fpcPixel->setMaxClassNo ( classNames->getMaxClassno() );
+  if ( !read_pixel_cache || !read_seg_cache )
+  {
+    // Generate Positioned Examples
+    SemSegTools::collectTrainingExamples ( conf, "FPCPixel", * ( ( *md ) ["train"] ), *classNames,
+                                           examples, imgexamples );
+  }
+
+  if ( ! read_pixel_cache )
+  {
+    ///////////////////////////////////
+    // Train Single Pixel Classifier
+    //////////////////////////////////
+
+    FeaturePool fp;
+    for ( vector<CachedExample *>::const_iterator k = imgexamples.begin();
+          k != imgexamples.end();
+          k++ )
+      fillCachePixel ( *k );
+
+    PixelPairFeature hf ( conf );
+    hf.explode ( fp );
+
+    fpcPixel->train ( fp, examples );
+    fpcPixel->save ( cachepixel );
+
+    fp.destroy();
+  } else {
+    fprintf ( stderr, "SemSegSTF:: Reading pixel classifier data from %s\n", cachepixel.c_str() );
+    fpcPixel->read ( cachepixel );
+  }
+
+  fpcSeg = new FPCRandomForests ( conf, "FPCSeg" );
+  fpcSeg->setMaxClassNo ( classNames->getMaxClassno() );
+  maxdepthSegmentationForest = conf->gI ( "bost", "maxdepth", 5 );
+  maxdepthSegmentationForestScores = conf->gI ( "bost", "maxdepth_scores", 9999 );
+
+  if ( ! read_seg_cache )
+  {
+    ///////////////////////////////////
+    // Train Segmentation Forest
+    //////////////////////////////////
+
+    fprintf ( stderr, "Calculating Prior Statistics\n" );
+    ProgressBar pbseg ( "Calculating Prior Statistics" );
+    pbseg.show();
+    for ( vector<CachedExample *>::const_iterator k = imgexamples.begin();
+          k != imgexamples.end();
+          k++ )
     {
-	// Generate Positioned Examples
-	SemSegTools::collectTrainingExamples ( conf, "FPCPixel", *((*md)["train"]), *classNames, 
-	    examples, imgexamples );
+      pbseg.update ( imgexamples.size() );
+      fillCacheSegmentation ( *k );
     }
+    pbseg.hide();
 
-    if ( ! read_pixel_cache ) 
-    {	
-	///////////////////////////////////
-	// Train Single Pixel Classifier
-	//////////////////////////////////
-
-	FeaturePool fp;
-	for ( vector<CachedExample *>::const_iterator k = imgexamples.begin(); 
-			k != imgexamples.end();
-			k++ )
-		fillCachePixel (*k);
-    
-	PixelPairFeature hf (conf);
-	hf.explode ( fp );
-
-	fpcPixel->train ( fp, examples );
-	fpcPixel->save ( cachepixel );
-
-	fp.destroy();
-    } else {
-	fprintf (stderr, "SemSegSTF:: Reading pixel classifier data from %s\n", cachepixel.c_str() );
-	fpcPixel->read ( cachepixel );
-    }
-    
-    fpcSeg = new FPCRandomForests ( conf, "FPCSeg" );
-    fpcSeg->setMaxClassNo ( classNames->getMaxClassno() );
-    maxdepthSegmentationForest = conf->gI("bost", "maxdepth", 5);
-    maxdepthSegmentationForestScores = conf->gI("bost", "maxdepth_scores", 9999);
+    FeaturePool fp;
 
-    if ( ! read_seg_cache ) 
+    if ( use_semantic_features )
     {
-	///////////////////////////////////
-	// Train Segmentation Forest
-	//////////////////////////////////
-
-	fprintf (stderr, "Calculating Prior Statistics\n");
-	ProgressBar pbseg ("Calculating Prior Statistics");
-	pbseg.show();
-	for ( vector<CachedExample *>::const_iterator k = imgexamples.begin(); 
-			    k != imgexamples.end();
-			    k++ )
-	{
-	    pbseg.update ( imgexamples.size() );
-	    fillCacheSegmentation ( *k );
-	}
-	pbseg.hide();
-	
-	FeaturePool fp;
-
-	if ( use_semantic_features )
-	{
-	    set<int> classnos;
-	    classNames->getSelection ( conf->gS("FPCSeg", "train_selection")
-		, classnos );
-	    SemanticFeature sf ( conf, &classnos );
-	    sf.explode ( fp );
-	}
-
-	fprintf (stderr, "Training Segmentation Forest\n");
-
-	fpcSeg->train ( fp, examples );
-	fpcSeg->save ( cacheseg );
-
-	// clean up memory !!
-	for ( vector<CachedExample *>::iterator i = imgexamples.begin();
-	    	    i != imgexamples.end();
-		    i++ )
-	    delete ( *i );
-
-	fp.destroy();
-	
-    } else {
-	fprintf (stderr, "SemSegSTF:: Reading region classifier data from %s\n", cacheseg.c_str() );
-	fpcSeg->read ( cacheseg );
-	fprintf (stderr, "SemSegSTF:: successfully read\n" );
+      set<int> classnos;
+      classNames->getSelection ( conf->gS ( "FPCSeg", "train_selection" )
+                                 , classnos );
+      SemanticFeature sf ( conf, &classnos );
+      sf.explode ( fp );
     }
+
+    fprintf ( stderr, "Training Segmentation Forest\n" );
+
+    fpcSeg->train ( fp, examples );
+    fpcSeg->save ( cacheseg );
+
+    // clean up memory !!
+    for ( vector<CachedExample *>::iterator i = imgexamples.begin();
+          i != imgexamples.end();
+          i++ )
+      delete ( *i );
+
+    fp.destroy();
+
+  } else {
+    fprintf ( stderr, "SemSegSTF:: Reading region classifier data from %s\n", cacheseg.c_str() );
+    fpcSeg->read ( cacheseg );
+    fprintf ( stderr, "SemSegSTF:: successfully read\n" );
+  }
 }
 
 SemSegSTF::~SemSegSTF()
@@ -142,83 +142,84 @@ SemSegSTF::~SemSegSTF()
 
 void SemSegSTF::fillCacheSegmentation ( CachedExample *ce )
 {
-    FIShotton::buildSemanticMap ( ce,
-		      fpcPixel,
-		      subsamplex,
-		      subsampley, 
-		      numClasses );
+  FIShotton::buildSemanticMap ( ce,
+                                fpcPixel,
+                                subsamplex,
+                                subsampley,
+                                numClasses );
 }
 
 void SemSegSTF::fillCachePixel ( CachedExample *ce )
 {
 }
 
-void SemSegSTF::semanticseg ( CachedExample *ce, 
-			   NICE::Image & segresult,
-			   NICE::MultiChannelImageT<double> & probabilities )
+void SemSegSTF::semanticseg ( CachedExample *ce,
+                              NICE::Image & segresult,
+                              NICE::MultiChannelImageT<double> & probabilities )
 {
-    int xsize;
-    int ysize;
-    ce->getImageSize ( xsize, ysize );
-    
-    int numClasses = classNames->numClasses();
-    
-    fillCachePixel ( ce );
-    fillCacheSegmentation ( ce );
-
-    fprintf (stderr, "BoST classification !\n");
-
-    Example pce ( ce, 0, 0 );
-
-    int xsize_s = xsize / subsamplex;
-    int ysize_s = ysize / subsampley;
-    ClassificationResult *results = new ClassificationResult [xsize_s*ysize_s];
-
-    /** classify each pixel of the image */
-    FullVector prior ( classNames->getMaxClassno() );
-    
-    probabilities.reInit ( xsize_s, ysize_s, numClasses, true );
-    probabilities.setAll ( 0 );
-
-    long offset_s = 0;
-    for ( int ys = 0 ; ys < ysize_s ; ys ++ ) 
-	for ( int xs = 0 ; xs < xsize_s ; xs++,offset_s++ )  
-	{
-	    int x = xs * subsamplex;
-	    int y = ys * subsampley;
-	    pce.x = x ; pce.y = y ; 
-	    results[offset_s] = fpcSeg->classify ( pce );
-
-	    for ( int i = 0 ; i < results[offset_s].scores.size(); i++ )
-		probabilities.data[i][offset_s] = results[offset_s].scores[i];
-
-	    /*
-	    if ( imagePriorMethod != IMAGE_PRIOR_NONE ) 
-		prior.add ( results[offset_s].scores );
-	    */
-	}
-
-   
-    fprintf (stderr, "BoST classification ready\n");
-
-    /** save results */
-    segresult.resize(xsize_s, ysize_s); 
-    segresult.set( classNames->classno("various") );
-
-    long int offset = 0;
-    for ( int y = 0 ; y < ysize_s ; y++ ) 
-	for ( int x = 0 ; x < xsize_s ; x++,offset++ )  
-	{
-	    double maxvalue = - numeric_limits<double>::max();
-	    int maxindex = 0;
-	    for ( int i = 0 ; i < (int)probabilities.numChannels; i++ )
-		if ( probabilities.data[i][offset] > maxvalue )
-		{
-		    maxindex = i;
-		    maxvalue = probabilities.data[i][offset];
-		}
-
-	    segresult.setPixel(x,y,maxindex);
-	}
+  int xsize;
+  int ysize;
+  ce->getImageSize ( xsize, ysize );
+
+  int numClasses = classNames->numClasses();
+
+  fillCachePixel ( ce );
+  fillCacheSegmentation ( ce );
+
+  fprintf ( stderr, "BoST classification !\n" );
+
+  Example pce ( ce, 0, 0 );
+
+  int xsize_s = xsize / subsamplex;
+  int ysize_s = ysize / subsampley;
+  ClassificationResult *results = new ClassificationResult [xsize_s*ysize_s];
+
+  /** classify each pixel of the image */
+  FullVector prior ( classNames->getMaxClassno() );
+
+  probabilities.reInit ( xsize_s, ysize_s, numClasses, true );
+  probabilities.setAll ( 0 );
+
+  long offset_s = 0;
+  for ( int ys = 0 ; ys < ysize_s ; ys ++ )
+    for ( int xs = 0 ; xs < xsize_s ; xs++, offset_s++ )
+    {
+      int x = xs * subsamplex;
+      int y = ys * subsampley;
+      pce.x = x ;
+      pce.y = y ;
+      results[offset_s] = fpcSeg->classify ( pce );
+
+      for ( int i = 0 ; i < results[offset_s].scores.size(); i++ )
+        probabilities.data[i][offset_s] = results[offset_s].scores[i];
+
+      /*
+      if ( imagePriorMethod != IMAGE_PRIOR_NONE )
+      prior.add ( results[offset_s].scores );
+      */
+    }
+
+
+  fprintf ( stderr, "BoST classification ready\n" );
+
+  /** save results */
+  segresult.resize ( xsize_s, ysize_s );
+  segresult.set ( classNames->classno ( "various" ) );
+
+  long int offset = 0;
+  for ( int y = 0 ; y < ysize_s ; y++ )
+    for ( int x = 0 ; x < xsize_s ; x++, offset++ )
+    {
+      double maxvalue = - numeric_limits<double>::max();
+      int maxindex = 0;
+      for ( int i = 0 ; i < ( int ) probabilities.numChannels; i++ )
+        if ( probabilities.data[i][offset] > maxvalue )
+        {
+          maxindex = i;
+          maxvalue = probabilities.data[i][offset];
+        }
+
+      segresult.setPixel ( x, y, maxindex );
+    }
 
 }

+ 45 - 45
semseg/SemSegSTF.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file SemSegSTF.h
 * @brief Localization system
 * @author Erik Rodner
@@ -17,65 +17,65 @@ namespace OBJREC {
 /** Localization system */
 class SemSegSTF : public SemanticSegmentation
 {
-    protected:
- 
-	int numClasses;
-	int maxdepthSegmentationForest;
-	int maxdepthSegmentationForestScores;
+  protected:
 
-	bool use_semantic_features;
-	bool use_pixelpair_features;
+    int numClasses;
+    int maxdepthSegmentationForest;
+    int maxdepthSegmentationForestScores;
 
-	int subsamplex;
-	int subsampley;
+    bool use_semantic_features;
+    bool use_pixelpair_features;
 
-	bool read_seg_cache;
-	bool read_pixel_cache;
+    int subsamplex;
+    int subsampley;
 
-	std::string cacheseg;
+    bool read_seg_cache;
+    bool read_pixel_cache;
 
-	std::string cachepixel;
+    std::string cacheseg;
 
-	std::string resultsdatadir;
+    std::string cachepixel;
 
-	double alphaDetectionPrior;
-	double alphaImagePrior;
-	
-	int imagePriorMethod;
-	int priorK;
+    std::string resultsdatadir;
 
-	int detectionPriorMethod;
+    double alphaDetectionPrior;
+    double alphaImagePrior;
 
-	/** 
-	    assign all pixels with
-	    normalized entropy $E/log(n)$ above
-	    this threshold to the
-	    background class 
-	*/
-	double entropyThreshold;
+    int imagePriorMethod;
+    int priorK;
 
-	int backgroundModelType;
+    int detectionPriorMethod;
 
-	std::map<DecisionNode *, std::pair<long, int> > index;
-	FPCRandomForests *fpcSeg;
-	FPCRandomForests *fpcPixel;
+    /**
+        assign all pixels with
+        normalized entropy $E/log(n)$ above
+        this threshold to the
+        background class
+    */
+    double entropyThreshold;
 
-	std::map<std::string, LocalizationResult *> detresults;
+    int backgroundModelType;
 
-	void fillCachePixel ( CachedExample *ce );
-	void fillCacheSegmentation ( CachedExample *ce );
+    std::map<DecisionNode *, std::pair<long, int> > index;
+    FPCRandomForests *fpcSeg;
+    FPCRandomForests *fpcPixel;
 
-    public:
-	/** simple constructor */
-	SemSegSTF( const Config *conf,
-  	              const MultiDataset *md );
-      
-	/** simple destructor */
-	virtual ~SemSegSTF();
+    std::map<std::string, LocalizationResult *> detresults;
 
-	void semanticseg ( CachedExample *ce, 
-			   NICE::Image & segresult,
-			   NICE::MultiChannelImageT<double> & probabilities );
+    void fillCachePixel ( CachedExample *ce );
+    void fillCacheSegmentation ( CachedExample *ce );
+
+  public:
+    /** simple constructor */
+    SemSegSTF ( const Config *conf,
+                const MultiDataset *md );
+
+    /** simple destructor */
+    virtual ~SemSegSTF();
+
+    void semanticseg ( CachedExample *ce,
+                       NICE::Image & segresult,
+                       NICE::MultiChannelImageT<double> & probabilities );
 };
 } // namespace
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác