123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /**
- * @file eccv2012-15scenes.cpp
- * @brief ECCV 2012 Experiment with 15 Scenes
- * @author Erik Rodner, Alexander Freytag
- * @date 01/17/2012
- */
- // STL includes
- #include <vector>
- // NICE-core includes
- #include <core/basics/vectorio.h>
- #include <core/basics/Timer.h>
- #include <core/basics/Config.h>
- // NICE-vislearning includes
- #include <vislearning/baselib/Globals.h>
- //
- #include <vislearning/cbaselib/MultiDataset.h>
- // gp-hik-core includes
- #include <gp-hik-core/FastMinKernel.h>
- #include <gp-hik-core/FMKGPHyperparameterOptimization.h>
- #include <gp-hik-core/tools.h>
- using namespace std;
- using namespace NICE;
- using namespace OBJREC;
- #include "datatools.h"
- /**
-
- ECCV 2012 Experiment with 15 Scenes
-
- NOTE: usage of this test-function is not recommended. Use eccv2012-15scenes-fasthik instaed with a proper interface
-
- */
- int main (int argc, char **argv)
- {
- std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
- Config conf ( argc, argv );
-
- string ext = conf.gS("main", "ext", ".txt");
- cerr << "Using cache extension: " << ext << endl;
- MultiDataset md ( &conf );
- const ClassNames & classNamesTrain = md.getClassNames("train");
-
- // read training set
- vector< vector<double> > trainData;
- NICE::Vector y;
- const LabeledSet *train = md["train"];
- readData< vector< vector<double> >, vector<double> > ( conf, *train, trainData, y, ext );
- std::cerr << " number of examples: " << trainData.size() << std::endl;
- transposeVectorOfVectors ( trainData );
- std::cerr << " number of dimensions: " << trainData.size() << std::endl;
- // DEBUG
- #if 0
- Quantization q ( conf.gI("GPHIKClassifier", "num_bins") );
- for ( uint i = 0 ; i < trainData.size() ; i++ )
- for ( uint j = 0 ; j < trainData[i].size(); j++ )
- trainData[i][j] = q.getPrototype ( q.quantize( trainData[i][j] ) );
- #endif
- // END DEBUG
- cerr << "Size of the training set: " << trainData.size() << endl;
- double noise = 0.1;
-
- Timer t;
- std::cerr << " create FastMinKernel object with data" << std::endl;
- t.start();
- FastMinKernel *fmk = new FastMinKernel ( trainData, noise );
- t.stop();
- std::cerr << " time for setting up FMK object: " << t.getLast() << std::endl;
-
- bool b_debug = conf.gB( "FMKGPHyperparameterOptimization", "debug", false);
-
- std::cerr << " debug: " << b_debug << std::endl;
-
- if ( b_debug )
- {
- fmk->store ( std::cerr );
- }
- std::cerr << " Initialize FMKGPHyperparameterOptimization object " << std::endl;
- t.start();
- FMKGPHyperparameterOptimization hyper ( &conf, fmk, "FMKGPHyperparameterOptimization" );
- t.stop();
- std::cerr << " time for setting up FMKGP object: " << t.getLast() << std::endl;
- std::cerr << " start optimization" << std::endl;
- t.start();
- hyper.optimize ( y );
- t.stop();
- std::cerr << " time for optimization: " << t.getLast() << std::endl;
-
-
- // ------------------ TESTING
- // q'n'd memory extensive solution
- const LabeledSet *test = md["test"];
- VVector testData;
- Vector yTest;
- readData< VVector, Vector > ( conf, *test, testData, yTest, ext );
- // DEBUG
- #if 0
- for ( uint i = 0 ; i < testData.size() ; i++ )
- for ( uint j = 0 ; j < testData[i].size(); j++ )
- testData[i][j] = q.getPrototype ( q.quantize( testData[i][j] ) );
- #endif
- //DEBUG END
- Matrix confusion ( y.Max()+1, yTest.Max() + 1, 0.0 );
- for ( uint i = 0 ; i < testData.size(); i++ )
- {
- const Vector & xstar = testData[i];
- // the following is just to be sure that we
- // do not count the time necessary for conversion
- SparseVector xstar_sparse ( xstar );
- uint classno_groundtruth = yTest[i];
- SparseVector scores;
- t.start();
- uint classno_estimated = hyper.classify ( xstar_sparse, scores );
- t.stop();
-
- scores.store(cerr);
- cerr << "[" << i << " / " << testData.size() << "] " << classno_estimated << " " << classno_groundtruth << " time: " << t.getLast() << endl;
- //confusion( classno_groundtruth, classno_estimated ) += 1;
- confusion( classno_estimated, classno_groundtruth ) += 1;
- }
- confusion.normalizeColumnsL1();
- cerr << confusion << endl;
- cerr << "average recognition rate: " << confusion.trace()/confusion.rows() << endl;
- return 0;
- }
|