123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #include <iostream>
- #include "core/basics/Config.h"
- #ifdef NICE_USELIB_MATIO
- #include "vislearning/cbaselib/ClassificationResults.h"
- #include "vislearning/baselib/ProgressBar.h"
- #include "core/matlabAccess/MatFileIO.h"
- #include "vislearning/matlabAccessHighLevel/ImageNetData.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"
- #include "vislearning/math/kernels/KernelRBF.h"
- #include "vislearning/math/kernels/KernelExp.h"
- using namespace std;
- using namespace NICE;
- using namespace OBJREC;
- int main (int argc, char **argv)
- {
- std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
- Config conf ( argc, argv );
- string resultsfile = conf.gS("main", "results", "results.txt" );
- int positiveClass = conf.gI("main", "positive_class");
- std::cerr << "Positive class is " << positiveClass << std::endl;
-
- sparse_t data;
- NICE::Vector y;
-
- std::cerr << "Reading ImageNet data ..." << std::endl;
- bool imageNetLocal = conf.gB("main", "imageNetLocal" , false);
- string imageNetPath;
- if (imageNetLocal)
- imageNetPath = "/users2/rodner/data/imagenet/devkit-1.0/";
- else
- imageNetPath = "/home/dbv/bilder/imagenet/devkit-1.0/";
- ImageNetData imageNet ( imageNetPath + "demo/" );
- LabeledSetVector train;
- imageNet.loadDataAsLabeledSetVector( train );
-
-
- double rbf_sigma = conf.gD("main", "rbf_sigma", -2.0 );
- KernelRBF kernelFunction ( rbf_sigma, 0.0 );
-
-
- string classifierName = conf.gS("main", "classifier", "KCGPApproxOneClass");
-
- KernelClassifier *classifier;
- if(strcmp("KCGPApproxOneClass",classifierName.c_str())==0)
- {
- classifier = new KCGPApproxOneClass ( &conf, &kernelFunction );
- }
- else if (strcmp("KCGPOneClass",classifierName.c_str())==0) {
- classifier = new KCGPOneClass ( &conf, &kernelFunction );
- }
- else{
- classifier = new KCGPApproxOneClass ( &conf, &kernelFunction );
- }
-
- classifier->teach( train );
-
-
- std::cerr << "Reading ImageNet test data files (takes some seconds)..." << std::endl;
- imageNet.preloadData ( "val", "testing" );
- imageNet.loadExternalLabels ( imageNetPath + "data/ILSVRC2010_validation_ground_truth.txt" );
-
- ClassificationResults results;
- std::cerr << "Classification step ... with " << imageNet.getNumPreloadedExamples() << " examples" << std::endl;
- ProgressBar pb;
- for ( uint i = 0 ; i < (uint)imageNet.getNumPreloadedExamples(); i++ )
- {
- pb.update ( imageNet.getNumPreloadedExamples() );
- const SparseVector & svec = imageNet.getPreloadedExample ( i );
- NICE::Vector vec;
- svec.convertToVectorT( vec );
-
- ClassificationResult r = classifier->classify ( vec );
-
-
- r.classno_groundtruth = (((int)imageNet.getPreloadedLabel ( i )) == positiveClass) ? 1 : 0;
- results.push_back ( r );
- }
- std::cerr << "Writing results to " << resultsfile << std::endl;
- results.writeWEKA ( resultsfile, 0 );
- double perfvalue = results.getBinaryClassPerformance( ClassificationResults::PERF_AUC );
- std::cerr << "Performance: " << perfvalue << std::endl;
-
-
- delete classifier;
-
- return 0;
- }
- #else
- int main (int argc, char **argv)
- {
- std::cerr << "MatIO library is missing in your system - this program will have no effect. " << std::endl;
- }
- #endif
|