Browse Source

ReadCache: allowed train and test differentiation in generic selection

Alexander Freytag 12 years ago
parent
commit
9572d980ff

+ 7 - 8
features/localfeatures/GenericLFSelection.h

@@ -137,7 +137,7 @@ class GenericLFSelection
           // write the features to a file, if there isn't any to read
           
           if ( useForTrainOrTest == TRAINING )
-          {
+          {    
             writeFeats = new LFWriteCache ( conf, lfrep, "cacheTrain" );
             lfrep = writeFeats;
           }
@@ -154,7 +154,6 @@ class GenericLFSelection
 
         }
 
-//TODO add the section into constructor for readCache
         if ( readfeat )
         {
           int numFeatures = conf->gI(section, "localfeature_count", -1);
@@ -163,30 +162,30 @@ class GenericLFSelection
           {
             if ( useForTrainOrTest == TRAINING )
             {
-              readFeats = new LFReadCache ( conf, writeFeats, numFeatures );
+              readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cacheTrain" );
             }
             else if ( useForTrainOrTest == TESTING )
             {
-              readFeats = new LFReadCache ( conf, writeFeats, numFeatures );
+              readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cacheTest" );
             }
             else //not specified whether for training or testing, so we do not care about
             {
-              readFeats = new LFReadCache ( conf, writeFeats, numFeatures );
+              readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cache" );
             }                         
           }
           else
           {
             if ( useForTrainOrTest == TRAINING )
             {
-              readFeats = new LFReadCache (conf, lfrep, numFeatures );
+              readFeats = new LFReadCache (conf, lfrep, numFeatures, "cacheTrain" );                        
             }
             else if ( useForTrainOrTest == TESTING )
             {
-              readFeats = new LFReadCache (conf, lfrep, numFeatures );
+              readFeats = new LFReadCache (conf, lfrep, numFeatures, "cacheTest" );
             }
             else //not specified whether for training or testing, so we do not care about
             {
-              readFeats = new LFReadCache (conf, lfrep, numFeatures );
+              readFeats = new LFReadCache (conf, lfrep, numFeatures, "cache" );
             }
           }
           lfrep = readFeats; 

+ 5 - 4
features/localfeatures/LFReadCache.cpp

@@ -20,14 +20,15 @@ using namespace NICE;
 
 LFReadCache::LFReadCache ( const Config *conf,
                            const LocalFeatureRepresentation *_lfrep,
-                           int _numFeatures ) : lfrep ( _lfrep )
+                           int _numFeatures,
+                           const std::string & _section ) : lfrep ( _lfrep )
 {
   //srand(time(NULL));
   numFeatures = _numFeatures;
-  cachedir = conf->gS ( "cache", "root" );
-  cachemode = Globals::getCacheMode ( conf->gS ( "cache", "mode", "cat" ) );
+  cachedir = conf->gS ( _section, "root" );
+  cachemode = Globals::getCacheMode ( conf->gS ( _section, "mode", "cat" ) );
 
-  std::string descFormat_s = conf->gS ( "cache", "descriptor_format", "binary_double" );
+  std::string descFormat_s = conf->gS ( _section, "descriptor_format", "binary_double" );
   if ( descFormat_s == "binary_double" )
     descFormat = VVector::FILEFORMAT_BINARY_DOUBLE;
   else if ( descFormat_s == "binary_uchar" )

+ 69 - 63
features/localfeatures/LFReadCache.h

@@ -1,7 +1,7 @@
 /** 
 * @file LFReadCache.h
 * @brief read local features from file
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @date 02/14/2008
 
 */
@@ -19,68 +19,74 @@
 
 namespace OBJREC {
 
-/** read local features from file */
-class LFReadCache : public LocalFeatureRepresentation
-{
-
-    protected:
-		int   numFeatures;
-		const LocalFeatureRepresentation *lfrep;
-		std::string cachedir;
-
-		int descFormat;
-		int cachemode;
-
-		template <class ImageClass>
-		int extractFeaturesTemplate ( const ImageClass & img, 
-				  NICE::VVector & features, 
-				  NICE::VVector & positions) const;
-
-    public:
-  
-	/** constructor 
-	 * @param conf Configuration
-	 * @param lfrep a LocalFeatureRepresentation (i.e. LFColorSande)
-	 * @param _numfeatures how many features should be returned (-1 for all)
-	 */
-	LFReadCache( const NICE::Config *conf, 
-		     const LocalFeatureRepresentation *lfrep,
-		     int _numFeatures = -1 );
-      
-	/** simple destructor */
-	virtual ~LFReadCache();
-
-	int getDescSize () const;
-
-	/**
-	 * extract features for gray images
-	 * @param img input image
-	 * @param features output features
-	 * @param positions position of the features
-	 * @return 
-	 */
-	int extractFeatures ( const NICE::Image & img, 
-			      NICE::VVector & features, 
-			      NICE::VVector & positions ) const;
-	
-	/**
-	 * extract features for color images
-	 * @param img input image
-	 * @param features output features
-	 * @param positions position of the features
-	 * @return 
-	 */
-	int extractFeatures ( const NICE::ColorImage & img, 
-			      NICE::VVector & features, 
-			      NICE::VVector & positions ) const;
-
-	void visualize ( NICE::Image & img, 
-		 const NICE::Vector & feature ) const;
-
-	void visualizeFeatures ( NICE::Image & mark,
-				 const NICE::VVector & positions,
-				 size_t color ) const;
-};
+  /** @class LFReadCache
+  * @brief Read local features from file
+  *
+  */   
+  class LFReadCache : public LocalFeatureRepresentation
+  {
+
+      protected:
+      int   numFeatures;
+      const LocalFeatureRepresentation *lfrep;
+      std::string cachedir;
+
+      int descFormat;
+      int cachemode;
+
+      template <class ImageClass>
+      int extractFeaturesTemplate ( const ImageClass & img, 
+            NICE::VVector & features, 
+            NICE::VVector & positions) const;
+
+      public:
+    
+    /** standard constructor 
+    * @param conf Configuration
+    * @param lfrep a LocalFeatureRepresentation (i.e. LFColorSande)
+    * @param _numfeatures how many features should be returned (-1 for all)
+    * @param _section specify the block in the config object we read 
+    */
+    LFReadCache( const NICE::Config *conf, 
+          const LocalFeatureRepresentation *lfrep,
+          int _numFeatures = -1,
+          const std::string & _section = "cache"          
+               );
+        
+    /** simple destructor */
+    virtual ~LFReadCache();
+
+    int getDescSize () const;
+
+    /**
+    * extract features for gray images
+    * @param img input image
+    * @param features output features
+    * @param positions position of the features
+    * @return 
+    */
+    int extractFeatures ( const NICE::Image & img, 
+              NICE::VVector & features, 
+              NICE::VVector & positions ) const;
+    
+    /**
+    * extract features for color images
+    * @param img input image
+    * @param features output features
+    * @param positions position of the features
+    * @return 
+    */
+    int extractFeatures ( const NICE::ColorImage & img, 
+              NICE::VVector & features, 
+              NICE::VVector & positions ) const;
+
+    void visualize ( NICE::Image & img, 
+      const NICE::Vector & feature ) const;
+
+    void visualizeFeatures ( NICE::Image & mark,
+          const NICE::VVector & positions,
+          size_t color ) const;
+  };
 
 } // namespace
 

+ 1 - 1
features/localfeatures/LFWriteCache.h

@@ -1,7 +1,7 @@
 /** 
 * @file LFWriteCache.h
 * @brief Write local features to file (whenever a descriptor is computed, it will be checked whether a corresponding file already exists. If not, we save the descriptor)
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @date 02/14/2008
 
 */

+ 2 - 2
math/cluster/GenericClusterAlgorithmSelection.h

@@ -49,7 +49,7 @@ namespace OBJREC {
         
           // string which defines the clustering technique
           std::string clusterTechnique = conf->gS(section, "clusterTechnique", "");
-        
+                  
           if ( clusterTechnique == "kmeans" )
           {
             clusterAlgo = new OBJREC::KMeans ( conf );
@@ -74,7 +74,7 @@ namespace OBJREC {
           {
             clusterAlgo = new OBJREC::SpectralCluster ( conf );
           }           
-          else if ( clusterTechnique == "random" )
+          else if ( clusterTechnique == "RandomClustering" )
           {
             clusterAlgo = new OBJREC::RandomClustering ( conf );
           }