Erik Rodner 9 жил өмнө
parent
commit
7b4cbf6bf6

+ 33 - 7
progs/eccv2012-15scenes-gphikclassifier.cpp

@@ -21,6 +21,7 @@
 
 // gp-hik-core includes
 #include <gp-hik-core/GPHIKClassifier.h>
+#include <gp-hik-core/GPHIKRawClassifier.h>
 #include <gp-hik-core/tools.h>
 
 using namespace std;
@@ -35,7 +36,8 @@ void readNonSparseAsSparseExamples ( const NICE::Config & conf,
                                      std::vector < const NICE::SparseVector * > & _examples, 
                                      NICE::Vector & _labels, 
                                      std::string extension = ".txt",
-                                     const bool _verbose = false
+                                     const bool _verbose = false,
+                                     int maxdim = -1
                                    )
 {
   std::string cacheroot = conf.gS("cache", "root");
@@ -60,7 +62,19 @@ void readNonSparseAsSparseExamples ( const NICE::Config & conf,
     std::ifstream ifs ( cachefn.c_str(), std::ios::in );
     if ( ! ifs.good() )
       fthrow(Exception, "File not found: " << cachefn );
+
     ifs >> x;
+
+    // reduce feature dimension if necessary
+    if (maxdim > 0 && x.size() > maxdim)
+    {
+        Vector xsub (maxdim);
+        for (int i = 0; i < maxdim; i++)
+            xsub[i] = x[i];
+        x = xsub;
+    }
+
+
     NICE::SparseVector * xSparse = new NICE::SparseVector ( x );
     _examples.push_back ( xSparse );
     ifs.close();
@@ -81,8 +95,11 @@ int main (int argc, char **argv)
   
   NICE::Config conf ( argc, argv );
  
-  NICE::GPHIKClassifier gphik ( &conf, "GPHIKClassifier" );   
-  
+  bool use_raw = conf.gB("main", "raw", false);
+
+  NICE::GPHIKClassifier gphik ( &conf, "GPHIKClassifier" );
+  NICE::GPHIKRawClassifier gphik_raw ( &conf, "GPHIKRawClassifier" );
+
   NICE::Timer t;  
   
   bool b_verbose = conf.gB ( "main", "b_verbose", false );
@@ -97,6 +114,7 @@ int main (int argc, char **argv)
   
   
   std::string ext = conf.gS("main", "ext", ".txt"); 
+  int maxdim = conf.gI("main", "maxdim", -1);
 //   cerr << "Using cache extension: " << ext << endl;
 
   MultiDataset md ( &conf );
@@ -115,7 +133,8 @@ int main (int argc, char **argv)
                                   examplesTrain, 
                                   labelsTrain, 
                                   ext,
-                                  b_verbose
+                                  b_verbose,
+                                  maxdim
                                 );  
   
   
@@ -127,7 +146,10 @@ int main (int argc, char **argv)
   std::cerr << " start training" << std::endl;
   t.start();
   
-  gphik.train ( examplesTrain, labelsTrain );
+  if (use_raw)
+      gphik_raw.train ( examplesTrain, labelsTrain );
+  else
+      gphik.train ( examplesTrain, labelsTrain );
 
   t.stop();
   std::cerr << " time for training: " << t.getLast() << std::endl;  
@@ -144,7 +166,8 @@ int main (int argc, char **argv)
                                   examplesTest, 
                                   labelsTest, 
                                   ext,
-                                  b_verbose
+                                  b_verbose,
+                                  maxdim
                                 );   
 
 
@@ -162,7 +185,10 @@ int main (int argc, char **argv)
 
     t.start();
     uint classno_estimated;
-    gphik.classify ( examplesTest[i], classno_estimated, scores );
+    if (use_raw)
+        gphik_raw.classify ( examplesTest[i], classno_estimated, scores );
+    else
+        gphik.classify ( examplesTest[i], classno_estimated, scores );
     t.stop();
     
     scores.store(cerr);