123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- /**
- * @file eccv2011-15scenes-fasthik.cpp
- * @brief ECCV 2012 Experiment with 15 Scenes
- * @author Erik Rodner
- * @date 01/17/2012
- */
- #include <vector>
- #include <core/basics/vectorio.h>
- #include <core/basics/Timer.h>
- #include <core/basics/Config.h>
- #include <vislearning/classifier/fpclassifier/gphik/FPCGPHIK.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/PFWeightedDim.h>
- #include <gp-hik-core/parameterizedFunctions/PFExp.h>
- #include <gp-hik-core/tools.h>
- using namespace std;
- using namespace NICE;
- using namespace OBJREC;
- #include "datatools.h"
- // this function is very much adapted to Wus files
- void readSparseExamples ( const string & fn, Examples & examples )
- {
- cerr << "Reading " << fn << endl;
- ifstream ifs ( fn.c_str(), ios::in );
- if ( ! ifs.good() ) {
- fthrow(Exception, "Unable to read " << fn );
- }
- while ( !ifs.eof() )
- {
- int classno;
- if ( !(ifs >> classno) ) break;
- classno--;
- SparseVector *v = new SparseVector;
- v->restore ( ifs, SparseVector::FORMAT_INDEX_LINE );
- v->setDim( 10000 );
- // evil HACK FIXME
- v->multiply(1.0 / (128.0*1000.0));
- Example example;
- example.svec = v;
- cerr << "read example of size " << v->size() << " belonging to class " << classno << endl;
- cerr << "min: " << v->min() << " max:" << v->max() << endl;
-
- examples.push_back ( pair<int, Example> ( classno, example ) );
- }
- ifs.close();
- }
- /**
-
- ECCV 2012 Experiment with 15 Scenes
-
- */
- int main (int argc, char **argv)
- {
- std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
- Config conf ( argc, argv );
-
- FPCGPHIK classifier ( &conf, "GPHIKClassifier" );
- string trainFilename = conf.gS("main", "train");
-
- Examples trainExamples;
- readSparseExamples ( trainFilename, trainExamples );
- FeaturePool fp; // ignored anyway
- classifier.train ( fp, trainExamples );
- cerr << "Reading test data file" << endl;
- string testFilename = conf.gS("main", "test");
- Examples testExamples;
- readSparseExamples ( testFilename, testExamples );
-
- Timer t;
- Matrix confusion ( 15, 15, 0.0 );
-
- int index = 1;
- for ( Examples::iterator example_i = testExamples.begin(); example_i != testExamples.end(); example_i++,index++ )
- {
- uint classno_groundtruth = example_i->first;
- t.start();
- ClassificationResult r = classifier.classify ( example_i->second );
- uint classno_estimated = r.classno;
- t.stop();
-
- r.scores.store(cerr);
- cerr << "[" << index << " / " << testExamples.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;
- }
|