forked from aclapes/segmenthreetion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModalityPrediction.h
162 lines (109 loc) · 4.22 KB
/
ModalityPrediction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// ModalityPrediction.h
// segmenthreetion
//
// Created by Albert Clapés on 02/03/14.
//
//
#ifndef __segmenthreetion__ModalityPrediction__
#define __segmenthreetion__ModalityPrediction__
#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/ml/ml.hpp>
#include "em.h"
#include "GridMat.h"
#include "ModalityGridData.hpp"
#include <boost/thread.hpp>
using namespace std;
template<typename Prediction>
class ModalityPredictionBase
{
public:
ModalityPredictionBase();
void setData(ModalityGridData& data);
void setModelSelection(bool flag);
void setModelSelectionParameters(int k, bool bGlobalBest = false);
void setValidationParameters(int k);
void setDimensionalityReduction(float variance);
void setTrainMirrored(bool flag);
void computeGridConsensusPredictions(cv::Mat& consensusPredictions, cv::Mat& consensusDistsToMargin);
void getAccuracy(cv::Mat predictions, cv::Mat& accuracies);
void getAccuracy(GridMat predictions, GridMat& accuracies);
void setPredictions(GridMat predictionsGrid);
void setDistsToMargin(GridMat distsToMarginGrid);
protected:
// Attributes
ModalityGridData m_data;
int m_hp, m_wp;
int m_seed;
int m_testK; // number of folds in outer cross-validation to obtain the test results
bool m_bModelSelection; // wheter to perform the selection or re-use an old one (in disk)
// files would be named: goodnesses_1.yml, ..., goodnesses_N.yml
// where N is equal to m_testK
int m_modelSelecK; // number of folds in inner cross-validation to perform model selection
bool m_bGlobalBest; // in model selection
bool m_bDimReduction;
float m_variance;
bool m_bTrainMirrored;
int m_narrowSearchSteps;
GridMat m_PredictionsGrid;
GridMat m_DistsToMarginGrid;
boost::mutex m_mutex;
};
template<typename Prediction>
class ModalityPrediction : public ModalityPredictionBase<Prediction>
{
ModalityPrediction();// : ModalityPredictionBase<Prediction>() {}
};
template<>
class ModalityPrediction<cv::EM40> : public ModalityPredictionBase<cv::EM40>
{
public:
ModalityPrediction();
void setNumOfMixtures(int m);
void setNumOfMixtures(vector<int> m);
void setEpsilons(float eps);
void setEpsilons(vector<float> eps);
void setLoglikelihoodThresholds(float t);
void setLoglikelihoodThresholds(vector<float> t);
template<typename T>
void modelSelection(GridMat descriptors, GridMat tags,
vector<vector<T> > params,
GridMat& goodnesses);
void predict(GridMat& predictions, GridMat& loglikelihoods, GridMat& distsToMargin); // this
void computeLoglikelihoodsDistribution(int nbins, double min, double max, cv::Mat& sbjDistribution, cv::Mat& objDistribution);
template<typename T>
void _modelSelection(GridMat descriptorsSbjTr, GridMat descriptorsSbjObjVal, GridMat tagsSbjObjVal,
int k, vector<vector<T> > params, GridMat& accs);
private:
// Attributes
vector<int> m_nmixtures;
vector<float> m_epsilons;
vector<float> m_logthresholds;
GridMat m_LoglikelihoodsGrid;
};
template<>
class ModalityPrediction<cv::Mat> : public ModalityPredictionBase<cv::Mat>
{
public:
ModalityPrediction();
void setPositiveClassificationRatios(float m);
void setPositiveClassificationRatios(vector<float> m);
void setScoreThresholds(float t);
void setScoreThresholds(vector<float> t);
template<typename T>
void modelSelection(cv::Mat gridsIndices, cv::Mat tags,
unsigned int i, unsigned int j,
cv::Mat params,
cv::Mat& goodness);
void predict(GridMat& predictions, GridMat& ramananScores, GridMat& distsToMargin); // this
private:
// Attributes
vector<float> m_ratios;
vector<float> m_scores;
GridMat m_RamananScoresGrid;
};
#endif /* defined(__segmenthreetion__ModalityPrediction__) */