/** * @file eccv2011-15scenes-fasthik.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" // 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 ( 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; }