|
@@ -24,6 +24,8 @@
|
|
|
#include "vislearning/featureLearning/FeatureLearningGeneric.h"
|
|
|
#include "vislearning/featureLearning/FeatureLearningClusterBased.h"
|
|
|
#include "vislearning/featureLearning/FeatureLearningRegionBased.h"
|
|
|
+//
|
|
|
+#include "vislearning/noveltyDetection/NDCodebookLevelImagePooling.h"
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
@@ -83,6 +85,15 @@ int main( int argc, char **argv )
|
|
|
std::cerr << "Unknown feature learning algorithm selected, use cluster based instead" << std::endl;
|
|
|
featureLearning = new OBJREC::FeatureLearningClusterBased( conf, &md );
|
|
|
}
|
|
|
+
|
|
|
+ //**********************************************
|
|
|
+ //
|
|
|
+ // SET UP THE NOVELTY DECTION ALGO
|
|
|
+ //
|
|
|
+ //**********************************************
|
|
|
+
|
|
|
+ OBJREC::NDCodebookLevelImagePooling * novDetector;
|
|
|
+ novDetector = new OBJREC::NDCodebookLevelImagePooling( conf, &md, "featureLearning" );
|
|
|
|
|
|
//evaluate how well the training images are covered with our initial codebook
|
|
|
//that is, compute these nice "novelty maps" per feature
|
|
@@ -116,6 +127,9 @@ int main( int argc, char **argv )
|
|
|
featureLearning->evaluateCurrentCodebookByConfusionMatrix( confusionMatInitial );
|
|
|
std::cerr << "initial Confusion matrix: " << std::endl << confusionMatInitial << std::endl;
|
|
|
|
|
|
+ //set the initially computed codebook to the novelty detection mechanism
|
|
|
+ //TODO this should be done, but currently we do not care about
|
|
|
+// novDetector->setCodebook( featureLearning->getCurrentCodebook() );
|
|
|
|
|
|
|
|
|
//**********************************************
|
|
@@ -137,7 +151,6 @@ int main( int argc, char **argv )
|
|
|
std::string filename = info.img();
|
|
|
|
|
|
NICE::ColorImage orig( filename );
|
|
|
-// showImage( orig, "Input" );
|
|
|
|
|
|
NICE::FloatImage noveltyImageBefore;
|
|
|
noveltyImageBefore = featureLearning->evaluateCurrentCodebookByDistance( filename , true /* beforeComputingNewFeatures */ );
|
|
@@ -150,24 +163,9 @@ int main( int argc, char **argv )
|
|
|
//
|
|
|
//**********************************************
|
|
|
|
|
|
- //TODO currently hard coded, and only stupid averaging of feature novelties for whole image, and hard thresholding!
|
|
|
- double meanNovelty ( 0.0 );
|
|
|
- for ( uint y = 0 ; y < ( uint ) noveltyImageBefore.height() ; y++ )
|
|
|
- {
|
|
|
- for ( uint x = 0 ; x < ( uint ) noveltyImageBefore.width(); x++ )
|
|
|
- {
|
|
|
- meanNovelty += noveltyImageBefore(x,y);
|
|
|
- }
|
|
|
- }
|
|
|
- int imageSize ( noveltyImageBefore.height() * noveltyImageBefore.width() );
|
|
|
- meanNovelty /= imageSize;
|
|
|
-
|
|
|
-// double stupidThreshold ( 0.0022 ); // for grid size 5
|
|
|
-// double stupidThreshold ( 0.01 ); // for grid size 3
|
|
|
- double stupidThreshold = conf->gD ( "featureLearning" , "stupidNoveltyThreshold", 0.0064 );
|
|
|
+ bool b_isImageNovel ( novDetector->evaluateNoveltyOfImage( noveltyImageBefore ) );
|
|
|
|
|
|
- std::cerr << " NOVELTY SCORE FOR CURRENT IMAGE: " << meanNovelty << " -- threshold: " << stupidThreshold << std::endl;
|
|
|
- if ( meanNovelty < stupidThreshold )
|
|
|
+ if ( ! b_isImageNovel )
|
|
|
{
|
|
|
std::cerr << " --- NOT NOVEL --- " << std::endl << std::endl;
|
|
|
continue;
|
|
@@ -185,6 +183,10 @@ int main( int argc, char **argv )
|
|
|
|
|
|
featureLearning->learnNewFeatures( filename );
|
|
|
|
|
|
+ //and update the codebook pointer within our novelty detection algorithm
|
|
|
+ //TODO this should be done, but currently we do not care about
|
|
|
+// novDetector->setCodebook( featureLearning->getCurrentCodebook() );
|
|
|
+
|
|
|
//**********************************************
|
|
|
//
|
|
|
// EVALUATE HOW WELL THE CURRENT IMAGE
|
|
@@ -253,5 +255,17 @@ int main( int argc, char **argv )
|
|
|
imageCnt++;
|
|
|
} //Loop over all test images
|
|
|
|
|
|
+
|
|
|
+ //don't waste memory
|
|
|
+ std::cerr << "don't waste memory - cleaning up" << std::endl;
|
|
|
+// if (trainFiles != NULL)
|
|
|
+// delete trainFiles;
|
|
|
+ if (featureLearning != NULL)
|
|
|
+ delete featureLearning;
|
|
|
+ if (novDetector != NULL)
|
|
|
+ delete novDetector;
|
|
|
+ if (conf != NULL)
|
|
|
+ delete conf;
|
|
|
+
|
|
|
return 0;
|
|
|
}
|