Bjoern Froehlich 13 жил өмнө
parent
commit
f86eb98f77
2 өөрчлөгдсөн 203 нэмэгдсэн , 184 устгасан
  1. 16 2
      semseg/SemSegCsurka.cpp
  2. 187 182
      semseg/SemSegCsurka.h

+ 16 - 2
semseg/SemSegCsurka.cpp

@@ -648,8 +648,6 @@ void SemSegCsurka::train ( const MultiDataset *md )
   // Merkmale berechnen //
   ////////////////////////
 
-  set<int> forbidden_classes;
-
   std::string forbidden_classes_s = conf->gS ( "analysis", "donttrain", "" );
   if ( forbidden_classes_s == "" )
   {
@@ -1504,6 +1502,19 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
           fV[j] += r.scores[j];
           preMap.set ( pce[i].second.x, pce[i].second.y, r.scores[j], j + s*klassen );
         }
+        
+        if(s == 0 && i == pce.size()/2)
+        {
+          cout << "scores: ";
+          for ( int j = 0 ; j < r.scores.size(); j++ )
+          {
+            if ( useclass[j] == 0 )
+              continue;
+            cout << r.scores[j] << " ";
+          }
+          cout << endl;
+        }
+        
       }
     }
   }
@@ -1544,6 +1555,9 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
 //#pragma omp parallel for
     for ( int i = 0; i < klassen; i++ )
     {
+      if ( forbidden_classes.find ( i ) != forbidden_classes.end() )
+        continue;
+      
       int pos = i + s * klassen;
 
       double maxval = preMap.data[pos][0];

+ 187 - 182
semseg/SemSegCsurka.h

@@ -1,4 +1,4 @@
-/** 
+/**
  * @file SemSegCsurka.h
  * @brief semantic segmentation using the method from Csurka08
  * @author Björn Fröhlich
@@ -29,7 +29,7 @@
 #include "objrec/segmentation/RSGraphBased.h"
 #include "objrec/segmentation/RSCache.h"
 
-#include "SemSegTools.h" 
+#include "SemSegTools.h"
 
 #include "vislearning/math/cluster/GMM.h"
 #include "vislearning/math/cluster/KMeansOnline.h"
@@ -54,191 +54,196 @@ class SemSegCsurka : public SemanticSegmentation
 {
 
   protected:
-	  
-	//! for normalization
-	std::vector<double> vecmin, vecmax;
-	  
-	//! boolean whether to save the cache or not
-	bool save_cache;
-	  
-	//! boolean whether to read the cache or not, if read_cache is false, everything will be trained
-	bool read_cache;
-	
-	//! The cached Data
-	std::string cache;
-	
-	//! The PCA
-	PCA pca;
-	
-	//! using normalization
-	bool norm;
-	
-	//! feature Dimension after PCA
-	int dim;
-	
-	//! Classifier
-	FeaturePoolClassifier *classifier;
-	VecClassifier *vclassifier;
-	
-	//! Configuration File
-	const Config *conf;	
-	
-	ClassNames cn;
-	
-	//! whether to use the colorfeats or not
-	bool usecolorfeats;
-	
-	//! low level Segmentation method
-	RegionSegmentationMethod *seg;
-	
-	//! weight for the gaussimage
-	double sigmaweight;
-	
-	//! Gaussian Mixture
-	GMM *g;
-	
-	//! KMeans
-	KMeansOnline *k;
-	
-	//! use pca or not
-	bool usepca;
-	
-	//! forced recalculation of the pca
-	bool calcpca;
-	
-	//! use highlevel transformation with gmm or not
-	bool usegmm;
-	
-	//! use highlevel transformation with kmeans or not
-	bool usekmeans;
-	
-	int bestclasses;
-	
-	//! how much clusters of the kmeans to use
-	int kmeansfeat;
-	
-	//! use hard assignment or not
-	bool kmeanshard;
-	
-	//! use fisher kernel for bag if visual words
-	bool usefisher;
-	
-	//! forced recalculation of the gmm
-	bool dogmm;
-	
-	//! number of gaussians
-	int gaussians;
-	
-	//! whether to use the relative location features or not
-	bool userellocprior;
-	
-	//! which classifier to use
-	std::string cname;
-	
-	//! use regions segmentation or not
-	bool useregions;
-	
-	//! how many features should be used for training the classifier (relative value between 0 and 1
-	double anteil;
-	
-	//! save steps for faster computing postprocesses
-	bool savesteps;
-	
-	//! the relative location features
-	RelativeLocationPrior *relloc;
-	
-	//! Shape pp
-	PPSuperregion *srg;
-	
-	//! Graph Cut pp
-	PPGraphCut *gcopt;
-	
-	//! smooth high level features or not
-	bool smoothhl;
-	
-	//! sigma for high level smoothing
-	double smoothfactor;
-	
-	//! which OpponentSIFT implementation to use {NICE, VANDESANDE}
-	std::string opSiftImpl;
-	
-	//! read features?
-	bool readfeat;
-	
-	//! write features?
-	bool writefeat;
-	
-	/**
-	 * converts the low level features in high level features
-	 * @param ex input and output features
-	 * @param reduce reduce the dataset (1.0 means no reduction)
-	 */
-	void convertLowToHigh(Examples &ex, double reduce = 1.0);
-		
-	/**
-	 * Starts the PCA
-	 * @param ex input features
-	 */
-	void initializePCA(Examples &ex);
-	
-	/**
-	 * using PCA on al input features
-	 * @param ex input features
-	 */
-	void doPCA(Examples &ex);
-	
-	/**
-	 * normalize the features between 0 and 1
-	 * @param ex input features
-	 */
-	void normalize(Examples &ex);
-	
-	
-	/**
-	 * smooth the high level features
-	 * @param ex input features
-	 */
-	void smoothHL(Examples ex);
-	
+
+    //! for normalization
+    std::vector<double> vecmin, vecmax;
+
+    //! boolean whether to save the cache or not
+    bool save_cache;
+
+    //! boolean whether to read the cache or not, if read_cache is false, everything will be trained
+    bool read_cache;
+
+    //! The cached Data
+    std::string cache;
+
+    //! The PCA
+    PCA pca;
+
+    //! using normalization
+    bool norm;
+
+    //! feature Dimension after PCA
+    int dim;
+
+    //! Classifier
+    FeaturePoolClassifier *classifier;
+    VecClassifier *vclassifier;
+
+    //! Configuration File
+    const Config *conf;
+
+
+    //! name of all classes
+    ClassNames cn;
+
+    //! set of forbidden/background classes
+    set<int> forbidden_classes;
+
+    //! whether to use the colorfeats or not
+    bool usecolorfeats;
+
+    //! low level Segmentation method
+    RegionSegmentationMethod *seg;
+
+    //! weight for the gaussimage
+    double sigmaweight;
+
+    //! Gaussian Mixture
+    GMM *g;
+
+    //! KMeans
+    KMeansOnline *k;
+
+    //! use pca or not
+    bool usepca;
+
+    //! forced recalculation of the pca
+    bool calcpca;
+
+    //! use highlevel transformation with gmm or not
+    bool usegmm;
+
+    //! use highlevel transformation with kmeans or not
+    bool usekmeans;
+
+    int bestclasses;
+
+    //! how much clusters of the kmeans to use
+    int kmeansfeat;
+
+    //! use hard assignment or not
+    bool kmeanshard;
+
+    //! use fisher kernel for bag if visual words
+    bool usefisher;
+
+    //! forced recalculation of the gmm
+    bool dogmm;
+
+    //! number of gaussians
+    int gaussians;
+
+    //! whether to use the relative location features or not
+    bool userellocprior;
+
+    //! which classifier to use
+    std::string cname;
+
+    //! use regions segmentation or not
+    bool useregions;
+
+    //! how many features should be used for training the classifier (relative value between 0 and 1
+    double anteil;
+
+    //! save steps for faster computing postprocesses
+    bool savesteps;
+
+    //! the relative location features
+    RelativeLocationPrior *relloc;
+
+    //! Shape pp
+    PPSuperregion *srg;
+
+    //! Graph Cut pp
+    PPGraphCut *gcopt;
+
+    //! smooth high level features or not
+    bool smoothhl;
+
+    //! sigma for high level smoothing
+    double smoothfactor;
+
+    //! which OpponentSIFT implementation to use {NICE, VANDESANDE}
+    std::string opSiftImpl;
+
+    //! read features?
+    bool readfeat;
+
+    //! write features?
+    bool writefeat;
+
+    /**
+     * converts the low level features in high level features
+     * @param ex input and output features
+     * @param reduce reduce the dataset (1.0 means no reduction)
+     */
+    void convertLowToHigh ( Examples &ex, double reduce = 1.0 );
+
+    /**
+     * Starts the PCA
+     * @param ex input features
+     */
+    void initializePCA ( Examples &ex );
+
+    /**
+     * using PCA on al input features
+     * @param ex input features
+     */
+    void doPCA ( Examples &ex );
+
+    /**
+     * normalize the features between 0 and 1
+     * @param ex input features
+     */
+    void normalize ( Examples &ex );
+
+
+    /**
+     * smooth the high level features
+     * @param ex input features
+     */
+    void smoothHL ( Examples ex );
+
   public:
-  
-	/** constructor 
-	  *  @param conf needs a configfile
-	  *  @param md and a MultiDataset (contains images and other things)
-	  */
-	SemSegCsurka( const Config *conf, const MultiDataset *md );
-      
-	/** simple destructor */
-	virtual ~SemSegCsurka();
-
-	/** The trainingstep
-	  *  @param md and a MultiDataset (contains images and other things)
-	  */
-	void train ( const MultiDataset *md );
-
-	/** The trainingstep for the postprocess
-	  *  @param md and a MultiDataset (contains images and other things)
-	  */
-	void trainpostprocess( const MultiDataset *md );
-	
-	/** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities
-	  * @param ce image data
-	  * @param segresult result of the semantic segmentation with a label for each pixel
-	  * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
-	  */
-	void semanticseg ( CachedExample *ce, 
+
+    /** constructor
+      *  @param conf needs a configfile
+      *  @param md and a MultiDataset (contains images and other things)
+      */
+    SemSegCsurka ( const Config *conf, const MultiDataset *md );
+
+    /** simple destructor */
+    virtual ~SemSegCsurka();
+
+    /** The trainingstep
+      *  @param md and a MultiDataset (contains images and other things)
+      */
+    void train ( const MultiDataset *md );
+
+    /** The trainingstep for the postprocess
+      *  @param md and a MultiDataset (contains images and other things)
+      */
+    void trainpostprocess ( const MultiDataset *md );
+
+    /** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities
+      * @param ce image data
+      * @param segresult result of the semantic segmentation with a label for each pixel
+      * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
+      */
+    void semanticseg ( CachedExample *ce,
                        NICE::Image & segresult,
                        NICE::MultiChannelImageT<double> & probabilities );
 
     /** this procedure is equal semanticseg, if there is no post process
-	  * @param ce image data
-	  * @param segresult result of the semantic segmentation with a label for each pixel
-	  * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
-	  * @param Regionen the output regions
-	  * @param mask the positions of the regions
-	  */
-	void classifyregions ( CachedExample *ce, NICE::Image & segresult, NICE::MultiChannelImageT<double> & probabilities, Examples &Regionen, NICE::Matrix &mask );
-    void getFeats(NICE::Image arg1, VVector arg2, VVector arg3);
+    * @param ce image data
+    * @param segresult result of the semantic segmentation with a label for each pixel
+    * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
+    * @param Regionen the output regions
+    * @param mask the positions of the regions
+    */
+    void classifyregions ( CachedExample *ce, NICE::Image & segresult, NICE::MultiChannelImageT<double> & probabilities, Examples &Regionen, NICE::Matrix &mask );
+    void getFeats ( NICE::Image arg1, VVector arg2, VVector arg3 );
 };
 
 } //namespace