1 #include "TrainNodeCvGMM.h" 2 #include "SamplesAccumulator.h" 31 Ptr<ml::EM> pEM = ml::EM::create();
49 for (Ptr<ml::EM> &em :
m_vpEM) em->clear();
55 std::string fileName =
generateFileName(path, name.empty() ?
"TrainNodeCvGMM_" + std::to_string(s) : name +
"_" + std::to_string(s), idx);
56 m_vpEM[s]->save(fileName.c_str());
63 std::string fileName =
generateFileName(path, name.empty() ?
"TrainNodeCvGMM_" + std::to_string(s) : name +
"_" + std::to_string(s), idx);
65 m_vpEM[s] = Algorithm::load<ml::EM>(fileName.c_str());
66 }
catch (Exception &) {
67 printf(
"In file: %s\n", fileName.c_str());
81 #ifdef DEBUG_PRINT_INFO 87 #ifdef DEBUG_PRINT_INFO 90 if (nSamples == 0)
continue;
101 featureVector.convertTo(fv, CV_64FC1);
105 float * pPot = potential.ptr<
float>(s);
106 byte * pMask = mask.ptr<byte>(s);
107 if (
m_vpEM[s]->isTrained())
void addFeatureVec(const Mat &featureVector, byte gt)
Adds new feature vector.
void init(TrainNodeCvGMMParams params)
void load(const std::string &path, const std::string &name=std::string(), short idx=-1)
Loads the training data.
int term_criteria_type
Termination cirteria type (according the the two previous parameters)
virtual ~CTrainNodeCvGMM(void)
void reset(void)
Resets class variables.
word getNumFeatures(void) const
Returns number of features.
std::string generateFileName(const std::string &path, const std::string &name, short idx) const
Generates name of the data file for storing random model parameters.
int getNumSamples(byte state) const
Returns the number of stored samples in container for the state (class) state.
word numGausses
The number of Gauss functions for approximation.
size_t maxSamples
Maximum number of samples to be used in training. 0 means using all the samples.
Base abstract class for random model training.
void release(byte state)
Releases memory of container for the state (class) state.
const TrainNodeCvGMMParams TRAIN_NODE_CV_GMM_PARAMS_DEFAULT
void addSample(const Mat &featureVector, byte state)
Adds new sample to the accumulator.
void reset(void)
Resets the accumulator.
static const double MIN_COEFFICIENT_BASE
int covariance_matrix_type
Type of the covariance matrix.
std::vector< Ptr< ml::EM > > m_vpEM
Expectation Maximization for GMM parameters estimation.
void calculateNodePotentials(const Mat &featureVector, Mat &potential, Mat &mask) const
Calculates the node potential, based on the feature vector.
int maxCount
Max number of iterations.
CTrainNodeCvGMM(byte nStates, word nFeatures, TrainNodeCvGMMParams params=TRAIN_NODE_CV_GMM_PARAMS_DEFAULT)
Constructor.
long double m_minCoefficient
Samples accumulator abstract class.
void train(bool doClean=false)
Random model training.
void save(const std::string &path, const std::string &name=std::string(), short idx=-1) const
Saves the training data.
double epsilon
GMM accuracy.
CSamplesAccumulator * m_pSamplesAcc
Samples Accumulator.
Base abstract class for node potentials training.
Mat getSamplesContainer(byte state) const
Returns samples container for the state (class) state.
int getNumInputSamples(byte state) const
Returns the number of input samples in container for the state (class) state.
byte m_nStates
The number of states (classes)
OpenCV Random Forest parameters.