FeatureLearningPrototypes.h 4.3 KB

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