/** * @file eccv2012-AwA.cpp * @brief ECCV 2012 Experiment with Animals with Attributes * @author Alexander Freytag * @date 06-02-2012 (dd-mm-yyyy) */ #include //---------- #include #include #include //---------- #include #include //---------- #include #include #include #include #include //---------- #include "datatools.h" using namespace std; using namespace NICE; using namespace OBJREC; /** ECCV 2012 Experiment with Animals with Attributes */ int main (int argc, char **argv) { std::set_terminate(__gnu_cxx::__verbose_terminate_handler); NICE::Config conf ( argc, argv ); string pf_s = conf.gS("main", "transform", "absexp"); int nrRuns = conf.gI("main", "nrRuns", 1); int dim = conf.gI("main", "dim", 2000); conf.sD( "FMKGPHyperparameterOptimization", "parameter_upper_bound", 5.0 ); conf.sD( "FMKGPHyperparameterOptimization", "parameter_lower_bound", 1.0 ); if ( pf_s == "absexp" ) conf.sS( "FMKGPHyperparameterOptimization", "transform", "absexp" ); else if ( pf_s == "exp" ) conf.sS( "FMKGPHyperparameterOptimization", "transform", "exp" ); else fthrow(Exception, "Parameterized function type " << pf_s << " not yet implemented"); std::cerr << "Transformation type: " << pf_s << std::endl; std::string ext = conf.gS("main", "ext", ".txt"); std::cerr << "Using cache extension: " << ext << std::endl; // read training set std::vector< std::vector > trainData; NICE::Vector y; double AARR(0.0); // averaged average recognition rate :) for (int run = 0; run < nrRuns; run++) { MultiDataset md ( &conf ); const ClassNames & classNamesTrain = md.getClassNames("train"); const LabeledSet *train = md["train"]; readData< vector< vector >, vector > ( conf, *train, trainData, y, ext ); //works correctly wit AwA transposeVectorOfVectors ( trainData ); // DEBUG #if 0 Quantization q ( conf.gI("HIKGP", "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 double noise = 0.1; FastMinKernel *fmk = new FastMinKernel ( trainData, noise, dim ); FMKGPHyperparameterOptimization hyper ( &conf, fmk ); hyper.optimize ( y ); // ------------------ TESTING // q'n'd memory extensive solution const LabeledSet *test = md["test"]; VVector testData; Vector yTest; readDataAwA ( conf, *test, testData, yTest, ext ); //ok, reading the data works also correctly with the AwA-dataformat // 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 ); //default tolerance is 10e-10 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.normalizeRowsL1(); cerr << confusion << endl; cerr << "average recognition rate: " << confusion.trace()/confusion.rows() << endl; AARR += confusion.trace()/confusion.rows(); // //don't waste memory; // delete train; // delete test; // delete fmk; } AARR /= (nrRuns); std::cerr << "final averaged recognition rate: " << AARR << std::endl; return 0; }