Erik Rodner 13 жил өмнө
parent
commit
aa74bc4f20

+ 2 - 2
cbaselib/ClassNames.cpp

@@ -17,10 +17,10 @@
 
 #include "vislearning/cbaselib/ClassNames.h"
 #include "core/basics/StringTools.h"
+#include "core/image/ImageTools.h"
 #include "vislearning/baselib/ICETools.h"
 
 using namespace OBJREC;
-
 using namespace std;
 using namespace NICE;
 
@@ -374,7 +374,7 @@ void ClassNames::getRGBColor ( int classno, int & r, int & g, int & b ) const
     getchar();
     double x = classno / ( double ) numClasses();
     double rd, gd, bd;
-    ICETools::toColor ( x, rd, gd, bd );
+    convertToPseudoColor ( x, rd, gd, bd );
     r = ( int ) ( 255 * rd );
     g = ( int ) ( 255 * gd );
     b = ( int ) ( 255 * bd );

+ 29 - 16
progs/testImageNetBinaryBruteForce.cpp

@@ -17,6 +17,7 @@
 
 #include "vislearning/cbaselib/ClassificationResults.h"
 #include "vislearning/baselib/ProgressBar.h"
+#include "vislearning/classifier/kernelclassifier/KCMinimumEnclosingBall.h"
 
 #include "fast-hik/tools.h"
 #include "fast-hik/MatFileIO.h"
@@ -258,11 +259,19 @@ void inline trainGPMean(NICE::Vector & GPMeanRightPart, const double & noise, co
     std::cerr << "Precise time used for GPMean training class " << classNumber << ": " << tTrainPrecise/CLOCKS_PER_SEC << std::endl;
 }    
 
-void inline trainSVDD( const double & noise, const NICE::Matrix kernelMatrix, const int & nrOfExamplesPerClass, const int & classNumber)
+KCMinimumEnclosingBall *trainSVDD( const double & noise, const NICE::Matrix kernelMatrix, const int & nrOfExamplesPerClass, const int & classNumber)
 {
-/*    Timer tTrainPrecise;
+ 
+    Config conf;
+    // set the outlier ratio (Paul optimized this paramter FIXME)
+    conf.sD( "SVDD", "outlier_fraction", 0.1 );
+    KCMinimumEnclosingBall *svdd = new KCMinimumEnclosingBall ( &conf, NULL /* no kernel function */, "SVDD" /* config section */ );
+
+    KernelData kernelData ( &conf, kernelMatrix, "Kernel" );
+ 
+ /*    Timer tTrainPrecise;
     tTrainPrecise.start();  */   
-    
+  
     //tic tTrainPrecise
     time_t  tTrainPreciseStart = clock();  
     
@@ -272,12 +281,17 @@ void inline trainSVDD( const double & noise, const NICE::Matrix kernelMatrix, co
     time_t  currentTime = clock();
     float tTrainPrecise = (float) (currentTime - tTrainPreciseStart);
     
-    //TODO!!!
+
     
+    NICE::Vector y(nrOfExamplesPerClass,1.0); //OCC setting :)
+    // KCMinimumEnclosingBall does not store the kernel data object, therefore, we are save with passing a local copy
+    svdd->teach ( &kernelData, y );
     
     std::cerr << "start time: " << tTrainPreciseStart << std::endl;
     std::cerr << "current time: " << currentTime << std::endl;
     std::cerr << "Precise time used for SVDD training class " << classNumber << ": " << tTrainPrecise/CLOCKS_PER_SEC << std::endl;
+
+    return svdd;
 }
 
 // ------------- EVALUATION METHODS ---------------------
@@ -374,22 +388,18 @@ void inline evaluateParzen(const NICE::Vector & kernelVector,  ClassificationRes
       r = ClassificationResult ( scores[1]<0.5 ? 0 : 1, scores );    
 }
 
-void inline evaluateSVDD(const NICE::Vector & kernelVector,  ClassificationResult & r, double & timeForSingleExamples)
+void inline evaluateSVDD( KCMinimumEnclosingBall *svdd, const NICE::Vector & kernelVector,  ClassificationResult & r, double & timeForSingleExamples)
 {
       Timer tTestSingle;
       tTestSingle.start();
       
       double score (0.0);
-      //TODO
-      
+     
+      // In the following, we assume that we are using a Gaussian kernel
+      r = svdd->classifyKernel ( kernelVector, 1.0 /* kernel self */ );
+
       tTestSingle.stop();
       timeForSingleExamples += tTestSingle.getLast();      
-      
-      FullVector scores ( 2 );
-      scores[0] = 0.0;
-      scores[1] = score;
-
-      r = ClassificationResult ( scores[1]<0.5 ? 0 : 1, scores );    
 }
 
 /** 
@@ -583,7 +593,7 @@ int main (int argc, char **argv)
     
     //train SVDD
     //TODO what do we need here?
-    trainSVDD(noiseSVDDParas[cl], kernelMatrix, nrOfExamplesPerClass, cl);
+    KCMinimumEnclosingBall *svdd = trainSVDD(noiseSVDDParas[cl], kernelMatrix, nrOfExamplesPerClass, cl);
   
     tTrain.stop();
     std::cerr << "Time used for training class " << cl << ": " << tTrain.getLast() << std::endl;      
@@ -651,7 +661,7 @@ int main (int argc, char **argv)
       
       //evaluate SVDD
       ClassificationResult rSVDD;
-      evaluateSVDD(kernelVector, rSVDD, timeForSingleExamplesSVDD);       
+      evaluateSVDD(svdd, kernelVector, rSVDD, timeForSingleExamplesSVDD);       
 
       
       // set ground truth label
@@ -712,7 +722,10 @@ int main (int argc, char **argv)
     OverallPerformanceGPMeanApprox += perfvalueGPMeanApprox;
     OverallPerformanceGPMean += perfvalueGPMean;
     OverallPerformanceParzen += perfvalueParzen;
-    OverallPerformanceSVDD += perfvalueSVDD;    
+    OverallPerformanceSVDD += perfvalueSVDD;   
+
+    // clean up memory used by SVDD
+    delete svdd;
   }
   
   OverallPerformanceGPVarApprox /= nrOfClassesToConcidere;