123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /**
- * @file testFeatureLearning.cpp
- * @brief test the feature learning routines to incrementally increase / adapt the codebook currently used
- * @author Alexander Freytag
- * @date 11-04-2013
- */
- #include <iostream>
- #include <limits>
- #include <core/basics/Config.h>
- #include <core/basics/ResourceStatistics.h>
- #include <core/vector/VectorT.h>
- #include <vislearning/baselib/Globals.h>
- #include <vislearning/baselib/ICETools.h>
- #include <vislearning/cbaselib/MultiDataset.h>
- #include <vislearning/cbaselib/Example.h>
- #include "vislearning/featureLearning/FeatureLearningGeneric.h"
- #include "vislearning/featureLearning/FeatureLearningClusterBased.h"
- using namespace std;
- using namespace NICE;
- using namespace OBJREC;
- /**
- test feature learning routines
- */
- int main( int argc, char **argv )
- {
- std::set_terminate( __gnu_cxx::__verbose_terminate_handler );
- Config * conf = new Config ( argc, argv );
-
- bool showTrainingImages= conf->gB( "featureLearning", "showTrainingImages", false );
- bool showTestImages= conf->gB( "featureLearning", "showTestImages", false );
-
- ResourceStatistics rs;
- std::string resultdir;
-
-
- //**********************************************
- //
- // READ INITIAL TRAINING SET TO COMPUTE
- // AN INITIAL CODEBOOK
- //
- //**********************************************
-
- std::cerr << " READ INITIAL TRAINING SET TO COMPUTE AN INITIAL CODEBOOK" << std::endl;
-
- MultiDataset md( conf );
- const LabeledSet *trainFiles = md["train"];
-
- //**********************************************
- //
- // SET UP THE FEATURE LEARNING ALGO
- //
- //**********************************************
-
- OBJREC::FeatureLearningGeneric * featureLearning;
- featureLearning = new OBJREC::FeatureLearningClusterBased( conf, &md );
-
- //print computed cluster centers -- this is NOT recommended :)
- // prototypes.store(std::cerr);
-
- //evaluate how well the training images are covered with our initial codebook
- //that is, compute these nice "novelty maps" per feature
-
- LOOP_ALL_S( *trainFiles )
- {
- EACH_INFO( classno, info );
- std::string filename = info.img();
-
- featureLearning->evaluateCurrentCodebook( filename );
- }
- //**********************************************
- //
- // FOR-LOOP OVER UNSEEN IMAGES
- //
- // EXTRACT FEATURES, CLUSTER THEM, TAKE
- // MOST "VALUABLE" CLUSTERS AS NEW
- // REPRESENTATIVES IN AN INCREASED CODEBOK
- //
- //**********************************************
- const LabeledSet *testFiles = md["test"];
-
- std::cerr << "start looping over all files" << std::endl;
- LOOP_ALL_S( *testFiles )
- {
- EACH_INFO( classno, info );
- std::string file = info.img();
-
- NICE::ColorImage orig( file );
- showImage( orig, "Input" );
- } //Loop over all test images
-
- return 0;
- }
|