|
@@ -14,8 +14,9 @@
|
|
|
#include "fast-hik/MatFileIO.h"
|
|
|
#include "fast-hik/ImageNetData.h"
|
|
|
|
|
|
-#include "vislearning/classifier/kernelclassifier/KCGPApproxOneClass.h"
|
|
|
#include "vislearning/classifier/kernelclassifier/KCGPOneClass.h"
|
|
|
+#include "vislearning/classifier/kernelclassifier/KCGPApproxOneClass.h"
|
|
|
+
|
|
|
|
|
|
#include "vislearning/math/kernels/KernelData.h"
|
|
|
#include "vislearning/math/kernels/Kernel.h"
|
|
@@ -54,7 +55,9 @@ int main (int argc, char **argv)
|
|
|
|
|
|
ImageNetData imageNet ( imageNetPath + "demo/" );
|
|
|
|
|
|
- imageNet.getBatchData ( data, y, "train", "training" );
|
|
|
+// imageNet.getBatchData ( data, y, "train", "training" );
|
|
|
+ LabeledSetVector train;
|
|
|
+ imageNet.loadDataAsLabeledSetVector( train );
|
|
|
|
|
|
//set up the kernel function
|
|
|
double rbf_sigma = conf.gD("main", "rbf_sigma", -2.0 );
|
|
@@ -76,38 +79,37 @@ int main (int argc, char **argv)
|
|
|
classifier = new KCGPApproxOneClass ( &conf, &kernelFunction );
|
|
|
}
|
|
|
//and perform the training
|
|
|
- //TODO how do we get a LabelSetSelection-Object out of our matlab data struct?
|
|
|
-// classifier->teach( train );
|
|
|
-
|
|
|
- uint n = y.size();
|
|
|
-
|
|
|
- set<int> positives;
|
|
|
- set<int> negatives;
|
|
|
-
|
|
|
- map< int, set<int> > mysets;
|
|
|
- for ( uint i = 0 ; i < n; i++ )
|
|
|
- mysets[ y[i] ].insert ( i );
|
|
|
-
|
|
|
- if ( mysets[ positiveClass ].size() == 0 )
|
|
|
- fthrow(Exception, "Class " << positiveClass << " is not available.");
|
|
|
-
|
|
|
- // add our positive examples
|
|
|
- for ( set<int>::const_iterator i = mysets[positiveClass].begin(); i != mysets[positiveClass].end(); i++ )
|
|
|
- positives.insert ( *i );
|
|
|
-
|
|
|
- int Nneg = conf.gI("main", "nneg", 1 );
|
|
|
- for ( map<int, set<int> >::const_iterator k = mysets.begin(); k != mysets.end(); k++ )
|
|
|
- {
|
|
|
- int classno = k->first;
|
|
|
- if ( classno == positiveClass )
|
|
|
- continue;
|
|
|
- const set<int> & s = k->second;
|
|
|
- uint ind = 0;
|
|
|
- for ( set<int>::const_iterator i = s.begin(); (i != s.end() && ind < Nneg); i++,ind++ )
|
|
|
- negatives.insert ( *i );
|
|
|
- }
|
|
|
- std::cerr << "Number of positive examples: " << positives.size() << std::endl;
|
|
|
- std::cerr << "Number of negative examples: " << negatives.size() << std::endl;
|
|
|
+ classifier->teach( train );
|
|
|
+
|
|
|
+// uint n = y.size();
|
|
|
+//
|
|
|
+// set<int> positives;
|
|
|
+// set<int> negatives;
|
|
|
+//
|
|
|
+// map< int, set<int> > mysets;
|
|
|
+// for ( uint i = 0 ; i < n; i++ )
|
|
|
+// mysets[ y[i] ].insert ( i );
|
|
|
+//
|
|
|
+// if ( mysets[ positiveClass ].size() == 0 )
|
|
|
+// fthrow(Exception, "Class " << positiveClass << " is not available.");
|
|
|
+//
|
|
|
+// // add our positive examples
|
|
|
+// for ( set<int>::const_iterator i = mysets[positiveClass].begin(); i != mysets[positiveClass].end(); i++ )
|
|
|
+// positives.insert ( *i );
|
|
|
+//
|
|
|
+// int Nneg = conf.gI("main", "nneg", 1 );
|
|
|
+// for ( map<int, set<int> >::const_iterator k = mysets.begin(); k != mysets.end(); k++ )
|
|
|
+// {
|
|
|
+// int classno = k->first;
|
|
|
+// if ( classno == positiveClass )
|
|
|
+// continue;
|
|
|
+// const set<int> & s = k->second;
|
|
|
+// uint ind = 0;
|
|
|
+// for ( set<int>::const_iterator i = s.begin(); (i != s.end() && ind < Nneg); i++,ind++ )
|
|
|
+// negatives.insert ( *i );
|
|
|
+// }
|
|
|
+// std::cerr << "Number of positive examples: " << positives.size() << std::endl;
|
|
|
+// std::cerr << "Number of negative examples: " << negatives.size() << std::endl;
|
|
|
|
|
|
// ------------------------------ TESTING ------------------------------
|
|
|
|