/** * @file eccv2012-15scenes.cpp * @brief ECCV 2012 Experiment with 15 Scenes * @author Erik Rodner * @date 01/17/2012 */ #include #include #include #include #include #include #include #include #include #include #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 pf_s = conf.gS("main", "transform", "absexp"); ParameterizedFunction *pf; double parameterLowerBound = conf.gD("GPHIKClassifier", "parameter_lower_bound", 1.0 ); double parameterUpperBound = conf.gD("GPHIKClassifier", "parameter_upper_bound", 5.0 ); if ( pf_s == "absexp" ) pf = new PFAbsExp( 1.0, parameterLowerBound, parameterUpperBound ); else if ( pf_s == "exp" ) pf = new PFExp ( 1.0, parameterLowerBound, parameterUpperBound ); else if ( pf_s == "weighted" ) pf = new PFWeightedDim ( conf.gI("main", "dimension"), 0.0, 5.0 ); else if ( pf_s == "MKL" ) { std::cerr << "use MKL feature transformation specific for VISAPP experiments" << std::endl; std::set steps; steps.insert(4000); steps.insert(6000); //specific for VISAPP pf = new PFMKL( steps, parameterLowerBound, parameterUpperBound ); } else fthrow(Exception, "Parameterized function type " << pf_s << " not yet implemented"); cerr << "Transformation type: " << pf_s << endl; 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; 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; FastMinKernel *fmk = new FastMinKernel ( trainData, noise ); FMKGPHyperparameterOptimization hyper ( &conf, pf, fmk ); hyper.optimize ( y ); // ------------------ 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 Timer t; 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; }