FeatureLearningClusterBased.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @file FeatureLearningClusterBased.h
  3. * @brief compute new histogram entries by clustering new features and take centers of clusters which are relevant and novel
  4. * @author Alexander Freytag
  5. * @date 16-04-2013 (dd-mm-yyyy)
  6. */
  7. #ifndef _INCLUDEFEATURELEARNINGCLUSTERBASED
  8. #define _INCLUDEFEATURELEARNINGCLUSTERBASED
  9. #include "FeatureLearningGeneric.h"
  10. #include <string>
  11. #include <core/vector/Distance.h>
  12. #include <core/vector/VVector.h>
  13. #include <vislearning/cbaselib/MultiDataset.h>
  14. #include <vislearning/features/localfeatures/GenericLocalFeatureSelection.h>
  15. #include <vislearning/math/cluster/ClusterAlgorithm.h>
  16. namespace OBJREC
  17. {
  18. /** abstract interface for feature learning algorithms */
  19. class FeatureLearningClusterBased : public FeatureLearningGeneric
  20. {
  21. protected:
  22. bool showTrainingImages;
  23. //! define the initial number of clusters our codebook shall contain
  24. int initialNumberOfClusters;
  25. //! define the number of clusters we want to compute for an unseen image
  26. int numberOfClustersForNewImage;
  27. OBJREC::ClusterAlgorithm * clusterAlgo;
  28. NICE::VectorDistance<double> * distFunction;
  29. LocalFeatureRepresentation * featureExtractor;
  30. NICE::VVector prototypes;
  31. bool showResults;
  32. std::string resultdir;
  33. int newImageCounter;
  34. //just needed for visualisation
  35. double oldMaxDist;
  36. //TODO stupid!!!
  37. double maxValForVisualization;
  38. /************************
  39. *
  40. * protected methods
  41. *
  42. **************************/
  43. void setClusterAlgo( const std::string & _clusterAlgoString, const bool & _setForInitialTraining);
  44. void extractFeaturesFromTrainingImages( const OBJREC::MultiDataset *_md, NICE::VVector & examplesTraining );
  45. void train ( const OBJREC::MultiDataset *_md );
  46. virtual bool loadInitialCodebook ( );
  47. virtual bool writeInitialCodebook ( );
  48. public:
  49. /** constructor
  50. * @param conf needs a configfile
  51. * @param md and a MultiDataset (contains images and other things)
  52. */
  53. FeatureLearningClusterBased ( const NICE::Config *_conf, const OBJREC::MultiDataset *_md , const std::string & _section = "featureLearning");
  54. /** simple destructor */
  55. virtual ~FeatureLearningClusterBased();
  56. /** this function has to be overloaded by all subclasses
  57. @param imgWithNovelContent
  58. */
  59. virtual void learnNewFeatures ( const std::string & filename ) ;
  60. virtual NICE::FloatImage evaluateCurrentCodebook ( const std::string & filename , const bool & beforeComputingNewFeatures = true );
  61. };
  62. } // namespace
  63. #endif