testFeatureLearning.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @file testFeatureLearning.cpp
  3. * @brief test the feature learning routines to incrementally increase / adapt the codebook currently used
  4. * @author Alexander Freytag
  5. * @date 11-04-2013
  6. */
  7. #include <iostream>
  8. #include <limits>
  9. #include <core/basics/Config.h>
  10. #include <core/basics/ResourceStatistics.h>
  11. #include <core/vector/VectorT.h>
  12. #include <vislearning/baselib/Globals.h>
  13. #include <vislearning/baselib/ICETools.h>
  14. #include <vislearning/cbaselib/MultiDataset.h>
  15. #include <vislearning/cbaselib/Example.h>
  16. #include "vislearning/featureLearning/FeatureLearningGeneric.h"
  17. #include "vislearning/featureLearning/FeatureLearningClusterBased.h"
  18. using namespace std;
  19. using namespace NICE;
  20. using namespace OBJREC;
  21. /**
  22. test feature learning routines
  23. */
  24. int main( int argc, char **argv )
  25. {
  26. std::set_terminate( __gnu_cxx::__verbose_terminate_handler );
  27. Config * conf = new Config ( argc, argv );
  28. bool showTrainingImages= conf->gB( "featureLearning", "showTrainingImages", false );
  29. bool showTestImages= conf->gB( "featureLearning", "showTestImages", false );
  30. ResourceStatistics rs;
  31. std::string resultdir;
  32. //**********************************************
  33. //
  34. // READ INITIAL TRAINING SET TO COMPUTE
  35. // AN INITIAL CODEBOOK
  36. //
  37. //**********************************************
  38. std::cerr << " READ INITIAL TRAINING SET TO COMPUTE AN INITIAL CODEBOOK" << std::endl;
  39. MultiDataset md( conf );
  40. const LabeledSet *trainFiles = md["train"];
  41. //**********************************************
  42. //
  43. // SET UP THE FEATURE LEARNING ALGO
  44. //
  45. //**********************************************
  46. OBJREC::FeatureLearningGeneric * featureLearning;
  47. featureLearning = new OBJREC::FeatureLearningClusterBased( conf, &md );
  48. //print computed cluster centers -- this is NOT recommended :)
  49. // prototypes.store(std::cerr);
  50. //evaluate how well the training images are covered with our initial codebook
  51. //that is, compute these nice "novelty maps" per feature
  52. LOOP_ALL_S( *trainFiles )
  53. {
  54. EACH_INFO( classno, info );
  55. std::string filename = info.img();
  56. featureLearning->evaluateCurrentCodebook( filename );
  57. }
  58. //**********************************************
  59. //
  60. // FOR-LOOP OVER UNSEEN IMAGES
  61. //
  62. // EXTRACT FEATURES, CLUSTER THEM, TAKE
  63. // MOST "VALUABLE" CLUSTERS AS NEW
  64. // REPRESENTATIVES IN AN INCREASED CODEBOK
  65. //
  66. //**********************************************
  67. const LabeledSet *testFiles = md["test"];
  68. std::cerr << "start looping over all files" << std::endl;
  69. LOOP_ALL_S( *testFiles )
  70. {
  71. EACH_INFO( classno, info );
  72. std::string file = info.img();
  73. NICE::ColorImage orig( file );
  74. showImage( orig, "Input" );
  75. } //Loop over all test images
  76. return 0;
  77. }