FeatureLearningPrototypes.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @file FeatureLearningPrototypes.h
  3. * @brief compute new histogram entries somehow, represent clusters only based on representatives, no additional information like dimensionwise variances...
  4. * @author Alexander Freytag
  5. * @date 17-04-2013 (dd-mm-yyyy)
  6. */
  7. #ifndef _INCLUDEFEATURELEARNINGPROTOTYPES
  8. #define _INCLUDEFEATURELEARNINGPROTOTYPES
  9. #include "FeatureLearningGeneric.h"
  10. #include <core/vector/Distance.h>
  11. #include <core/vector/VVector.h>
  12. #include <vislearning/cbaselib/MultiDataset.h>
  13. //
  14. #include <vislearning/features/localfeatures/GenericLocalFeatureSelection.h>
  15. //
  16. #include <vislearning/math/cluster/ClusterAlgorithm.h>
  17. namespace OBJREC
  18. {
  19. /**
  20. * @class FeatureLearningPrototypes
  21. * @brief compute new histogram entries somehow, represent clusters only based on representatives, no additional information like dimensionwise variances...
  22. * @author Alexander Freytag
  23. * @date 17-04-2013 (dd-mm-yyyy)
  24. */
  25. class FeatureLearningPrototypes : public FeatureLearningGeneric
  26. {
  27. protected:
  28. /************************
  29. *
  30. * protected variables
  31. *
  32. **************************/
  33. bool showTrainingImages;
  34. //! define the initial number of clusters our codebook shall contain
  35. int initialNumberOfClusters;
  36. OBJREC::ClusterAlgorithm * clusterAlgo;
  37. NICE::VectorDistance<double> * distFunction;
  38. LocalFeatureRepresentation * featureExtractor;
  39. //! The currently known "cluster" centers, which are used for BoW histogram computation
  40. NICE::VVector prototypes;
  41. int newImageCounter;
  42. //just needed for visualisation
  43. double oldMaxDist;
  44. //TODO stupid!!!
  45. double maxValForVisualization;
  46. //! just for temporary debugging
  47. int i_posXOfNewPrototype;
  48. int i_posYOfNewPrototype;
  49. /************************
  50. *
  51. * protected methods
  52. *
  53. **************************/
  54. void setClusterAlgo( const std::string & _clusterAlgoString);
  55. void setFeatureExtractor( const bool & _setForTraining = false);
  56. void extractFeaturesFromTrainingImages( const OBJREC::MultiDataset *_md, NICE::VVector & examplesTraining );
  57. void train ( const OBJREC::MultiDataset *_md );
  58. virtual bool loadInitialCodebook ( );
  59. virtual bool writeInitialCodebook ( );
  60. virtual void evaluateCurrentCodebookForGivenFeatures ( const NICE::VVector & _features,
  61. const NICE::VVector & _positions,
  62. NICE::FloatImage & _noveltyImageGaussFiltered,
  63. NICE::FloatImage * _noveltyImage = NULL
  64. );
  65. public:
  66. /** constructor
  67. * @param _conf needs a configfile
  68. * @param _md and a MultiDataset (contains images and other things)
  69. * @param _section section information for parsing config files
  70. */
  71. FeatureLearningPrototypes ( const NICE::Config *_conf, const OBJREC::MultiDataset *_md , const std::string & _section = "featureLearning");
  72. /** simple destructor */
  73. virtual ~FeatureLearningPrototypes();
  74. /** this function has to be overloaded by all subclasses
  75. @param imgWithNovelContent
  76. */
  77. virtual void learnNewFeatures ( const std::string & _filename ) = 0 ;
  78. virtual NICE::FloatImage evaluateCurrentCodebookByDistance ( const std::string & _filename , const bool & beforeComputingNewFeatures = true );
  79. virtual NICE::ImageT<int> evaluateCurrentCodebookByAssignments ( const std::string & _filename , const bool & beforeComputingNewFeatures = true, const bool & _binaryShowLatestPrototype = false);
  80. virtual void evaluateCurrentCodebookByConfusionMatrix( NICE::Matrix & _confusionMat );
  81. virtual NICE::VVector * getCurrentCodebook();
  82. };
  83. } // namespace
  84. #endif