2012-06-08 22:54:17 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
2012-11-09 15:29:52 +08:00
|
|
|
# if defined __clang__ || defined __APPLE__
|
2012-10-25 00:36:30 +08:00
|
|
|
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
|
|
|
# pragma GCC diagnostic ignored "-Wextra"
|
|
|
|
# endif
|
2012-06-08 22:54:17 +08:00
|
|
|
#endif
|
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
|
|
|
#define __OPENCV_TEST_PRECOMP_HPP__
|
|
|
|
|
2013-03-15 00:10:54 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
2013-03-13 20:22:44 +08:00
|
|
|
#include "opencv2/ts.hpp"
|
|
|
|
#include "opencv2/ml.hpp"
|
2011-02-10 04:55:11 +08:00
|
|
|
#include "opencv2/core/core_c.h"
|
|
|
|
|
|
|
|
#define CV_NBAYES "nbayes"
|
|
|
|
#define CV_KNEAREST "knearest"
|
|
|
|
#define CV_SVM "svm"
|
|
|
|
#define CV_EM "em"
|
|
|
|
#define CV_ANN "ann"
|
|
|
|
#define CV_DTREE "dtree"
|
|
|
|
#define CV_BOOST "boost"
|
|
|
|
#define CV_RTREES "rtrees"
|
|
|
|
#define CV_ERTREES "ertrees"
|
2016-01-20 17:59:44 +08:00
|
|
|
#define CV_SVMSGD "svmsgd"
|
2011-02-10 04:55:11 +08:00
|
|
|
|
2014-07-30 03:54:23 +08:00
|
|
|
enum { CV_TRAIN_ERROR=0, CV_TEST_ERROR=1 };
|
|
|
|
|
|
|
|
using cv::Ptr;
|
|
|
|
using cv::ml::StatModel;
|
|
|
|
using cv::ml::TrainData;
|
|
|
|
using cv::ml::NormalBayesClassifier;
|
|
|
|
using cv::ml::SVM;
|
|
|
|
using cv::ml::KNearest;
|
|
|
|
using cv::ml::ParamGrid;
|
|
|
|
using cv::ml::ANN_MLP;
|
|
|
|
using cv::ml::DTrees;
|
|
|
|
using cv::ml::Boost;
|
|
|
|
using cv::ml::RTrees;
|
2016-01-20 17:59:44 +08:00
|
|
|
using cv::ml::SVMSGD;
|
2014-07-30 03:54:23 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
class CV_MLBaseTest : public cvtest::BaseTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_MLBaseTest( const char* _modelName );
|
|
|
|
virtual ~CV_MLBaseTest();
|
|
|
|
protected:
|
|
|
|
virtual int read_params( CvFileStorage* fs );
|
|
|
|
virtual void run( int startFrom );
|
|
|
|
virtual int prepare_test_case( int testCaseIdx );
|
|
|
|
virtual std::string& get_validation_filename();
|
|
|
|
virtual int run_test_case( int testCaseIdx ) = 0;
|
|
|
|
virtual int validate_test_results( int testCaseIdx ) = 0;
|
|
|
|
|
|
|
|
int train( int testCaseIdx );
|
2014-07-30 03:54:23 +08:00
|
|
|
float get_test_error( int testCaseIdx, std::vector<float> *resp = 0 );
|
2011-02-10 04:55:11 +08:00
|
|
|
void save( const char* filename );
|
|
|
|
void load( const char* filename );
|
|
|
|
|
2014-07-30 03:54:23 +08:00
|
|
|
Ptr<TrainData> data;
|
2011-02-10 04:55:11 +08:00
|
|
|
std::string modelName, validationFN;
|
|
|
|
std::vector<std::string> dataSetNames;
|
|
|
|
cv::FileStorage validationFS;
|
|
|
|
|
2014-07-30 03:54:23 +08:00
|
|
|
Ptr<StatModel> model;
|
2011-02-10 04:55:11 +08:00
|
|
|
|
|
|
|
std::map<int, int> cls_map;
|
|
|
|
|
|
|
|
int64 initSeed;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CV_AMLTest : public CV_MLBaseTest
|
|
|
|
{
|
|
|
|
public:
|
2012-06-25 19:24:06 +08:00
|
|
|
CV_AMLTest( const char* _modelName );
|
2014-07-30 03:54:23 +08:00
|
|
|
virtual ~CV_AMLTest() {}
|
2011-02-10 04:55:11 +08:00
|
|
|
protected:
|
|
|
|
virtual int run_test_case( int testCaseIdx );
|
|
|
|
virtual int validate_test_results( int testCaseIdx );
|
|
|
|
};
|
|
|
|
|
|
|
|
class CV_SLMLTest : public CV_MLBaseTest
|
|
|
|
{
|
|
|
|
public:
|
2012-06-25 19:24:06 +08:00
|
|
|
CV_SLMLTest( const char* _modelName );
|
2014-07-30 03:54:23 +08:00
|
|
|
virtual ~CV_SLMLTest() {}
|
2011-02-10 04:55:11 +08:00
|
|
|
protected:
|
|
|
|
virtual int run_test_case( int testCaseIdx );
|
|
|
|
virtual int validate_test_results( int testCaseIdx );
|
|
|
|
|
|
|
|
std::vector<float> test_resps1, test_resps2; // predicted responses for test data
|
2011-04-11 22:47:06 +08:00
|
|
|
std::string fname1, fname2;
|
2011-02-10 04:55:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|