123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- /**
- * @file eccv2012-AwA.cpp
- * @brief ECCV 2012 Experiment with Animals with Attributes
- * @author Alexander Freytag
- * @date 06-02-2012 (dd-mm-yyyy)
- */
- #include <vector>
- //----------
- #include <core/basics/vectorio.h>
- #include <core/basics/Timer.h>
- #include <core/basics/Config.h>
- //----------
- #include <vislearning/cbaselib/MultiDataset.h>
- #include <vislearning/baselib/Globals.h>
- //----------
- #include <gp-hik-core/FastMinKernel.h>
- #include <gp-hik-core/FMKGPHyperparameterOptimization.h>
- #include <gp-hik-core/parameterizedFunctions/PFAbsExp.h>
- #include <gp-hik-core/parameterizedFunctions/PFExp.h>
- #include <gp-hik-core/tools.h>
- //----------
- #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<double> > 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<double> >, vector<double> > ( 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;
- }
|