/** * @file eccv2012-15scenes.cpp * @brief ECCV 2012 Experiment with 15 Scenes * @author Erik Rodner, Alexander Freytag * @date 01/17/2012 */ // STL includes #include // NICE-core includes #include #include #include // NICE-vislearning includes #include // #include // gp-hik-core includes #include #include #include 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 > trainData; NICE::Vector y; const LabeledSet *train = md["train"]; readData< vector< vector >, vector > ( conf, *train, trainData, y, ext ); transposeVectorOfVectors ( trainData ); // 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; 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; }