FeatureLearningPrototypes.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /************************
  47. *
  48. * protected methods
  49. *
  50. **************************/
  51. void setClusterAlgo( const std::string & _clusterAlgoString);
  52. void setFeatureExtractor( const bool & _setForTraining = false);
  53. void extractFeaturesFromTrainingImages( const OBJREC::MultiDataset *_md, NICE::VVector & examplesTraining );
  54. void train ( const OBJREC::MultiDataset *_md );
  55. virtual bool loadInitialCodebook ( );
  56. virtual bool writeInitialCodebook ( );
  57. virtual void evaluateCurrentCodebookForGivenFeatures ( const NICE::VVector & _features,
  58. const NICE::VVector & _positions,
  59. NICE::FloatImage & _noveltyImageGaussFiltered,
  60. NICE::FloatImage * _noveltyImage = NULL
  61. );
  62. public:
  63. /** constructor
  64. * @param _conf needs a configfile
  65. * @param _md and a MultiDataset (contains images and other things)
  66. */
  67. FeatureLearningPrototypes ( const NICE::Config *_conf, const OBJREC::MultiDataset *_md , const std::string & _section = "featureLearning");
  68. /** simple destructor */
  69. virtual ~FeatureLearningPrototypes();
  70. /** this function has to be overloaded by all subclasses
  71. @param imgWithNovelContent
  72. */
  73. virtual void learnNewFeatures ( const std::string & _filename ) = 0 ;
  74. virtual NICE::FloatImage evaluateCurrentCodebookByDistance ( const std::string & _filename , const bool & beforeComputingNewFeatures = true );
  75. virtual NICE::ImageT<int> evaluateCurrentCodebookByAssignments ( const std::string & _filename , const bool & beforeComputingNewFeatures = true, const bool & _binaryShowLatestPrototype = false);
  76. };
  77. } // namespace
  78. #endif