Direct Graphical Models
v.1.7.0
|
Gaussian Mixture Model training class. More...
#include <TrainNodeGMM.h>
Public Member Functions | |
CTrainNodeGMM (byte nStates, word nFeatures, TrainNodeGMMParams params=TRAIN_NODE_GMM_PARAMS_DEFAULT) | |
Constructor. More... | |
CTrainNodeGMM (byte nStates, word nFeatures, byte maxGausses) | |
Constructor. More... | |
virtual | ~CTrainNodeGMM (void) |
void | reset (void) |
Resets class variables. More... | |
void | addFeatureVec (const Mat &featureVector, byte gt) |
Adds new feature vector. More... | |
void | train (bool doClean=false) |
Random model training. More... | |
Public Member Functions inherited from DirectGraphicalModels::CTrainNode | |
CTrainNode (byte nStates, word nFeatures) | |
Constructor. More... | |
virtual | ~CTrainNode (void)=default |
void | addFeatureVecs (const Mat &featureVectors, const Mat >) |
Adds a block of new feature vectors. More... | |
void | addFeatureVecs (const vec_mat_t &featureVectors, const Mat >) |
Adds a block of new feature vectors. More... | |
Mat | getNodePotentials (const Mat &featureVectors, const Mat &weights=Mat(), float Z=0.0f) const |
Returns a block of node potentials, based on the block of feature vector. More... | |
Mat | getNodePotentials (const vec_mat_t &featureVectors, const Mat &weights=Mat(), float Z=0.0f) const |
Returns a block of node potentials, based on the block of feature vector. More... | |
Mat | getNodePotentials (const Mat &featureVector, float weight, float Z=0.0f) const |
Returns the node potential, based on the feature vector. More... | |
Public Member Functions inherited from DirectGraphicalModels::ITrain | |
ITrain (byte nStates, word nFeatures) | |
Constructor. More... | |
virtual | ~ITrain (void)=default |
word | getNumFeatures (void) const |
Returns number of features. More... | |
Public Member Functions inherited from DirectGraphicalModels::CBaseRandomModel | |
CBaseRandomModel (byte nStates) | |
Constructor. More... | |
virtual | ~CBaseRandomModel (void) |
virtual void | save (const std::string &path, const std::string &name=std::string(), short idx=-1) const |
Saves the training data. More... | |
virtual void | load (const std::string &path, const std::string &name=std::string(), short idx=-1) |
Loads the training data. More... | |
byte | getNumStates (void) const |
Returns number of states (classes) More... | |
Protected Member Functions | |
void | saveFile (FILE *pFile) const |
Saves the random model into the file. More... | |
void | loadFile (FILE *pFile) |
Loads the random model from the file. More... | |
void | calculateNodePotentials (const Mat &featureVector, Mat &potential, Mat &mask) const |
Calculates the node potential, based on the feature vector. More... | |
Protected Member Functions inherited from DirectGraphicalModels::CBaseRandomModel | |
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. More... | |
Private Attributes | |
TrainNodeGMMParams | m_params |
std::vector< GaussianMixture > | m_vGaussianMixtures |
long double | m_minAlpha = 1 |
Static Private Attributes | |
static const size_t | MIN_SAMPLES = 16 |
static const long double | MAX_COEFFICIENT = 1.0 |
Additional Inherited Members | |
Static Public Member Functions inherited from DirectGraphicalModels::CTrainNode | |
static std::shared_ptr< CTrainNode > | create (byte nodeRandomModel, byte nStates, word nFeatures) |
Factory method returning node trainer object. More... | |
Protected Attributes inherited from DirectGraphicalModels::CBaseRandomModel | |
byte | m_nStates |
The number of states (classes) More... | |
Gaussian Mixture Model training class.
This class implements the generative training mechanism, based on the idea of approximating the density of multi-dimensional random variables with an additive super-position of multivariate Gaussian distributions. The underlying algorithm is described in the paper Sequential Gaussian Mixture Models for Two-Level Conditional Random Fields
Definition at line 40 of file TrainNodeGMM.h.
DirectGraphicalModels::CTrainNodeGMM::CTrainNodeGMM | ( | byte | nStates, |
word | nFeatures, | ||
TrainNodeGMMParams | params = TRAIN_NODE_GMM_PARAMS_DEFAULT |
||
) |
Constructor.
nStates | Number of states (classes) |
nFeatures | Number of features |
params | Gaussian Mixture Model parameters (Ref. TrainNodeGMMParams) |
Definition at line 11 of file TrainNodeGMM.cpp.
DirectGraphicalModels::CTrainNodeGMM::CTrainNodeGMM | ( | byte | nStates, |
word | nFeatures, | ||
byte | maxGausses | ||
) |
Constructor.
nStates | Number of states (classes) |
nFeatures | Number of features |
maxGausses | The maximal number of mixture components in the Gaussian Mixture Model per state (class) |
Definition at line 23 of file TrainNodeGMM.cpp.
|
virtual |
Definition at line 35 of file TrainNodeGMM.cpp.
|
virtual |
Adds new feature vector.
Used to add a featureVector, corresponding to the ground-truth state (class) gt for training
featureVector | Multi-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1) |
gt | Corresponding ground-truth state (class) |
Implements DirectGraphicalModels::CTrainNode.
Definition at line 71 of file TrainNodeGMM.cpp.
|
protectedvirtual |
Calculates the node potential, based on the feature vector.
This function calculates the potentials of the node, described with the sample featureVector ( \( \textbf{f} \)): \( nodePot_s = \sum^{nGaussians_s}_{i=1}\pi_{i,s}\cdot\mathcal{N}_{i,s}(\textbf{f}), \forall s \in \mathbb{S} \), where \(\mathbb{S}\) is the set of all states (classes) and \(\pi\) is a weighted coefficient. In other words, the indexes: \( s \in [0; nStates) \). Here \( \mathcal{N} \) is a Gaussian function kernel, described in class CKDGauss
[in] | featureVector | Multi-dimensinal point \(\textbf{f}\): Mat(size: nFeatures x 1; type: CV_{XX}C1) |
[in,out] | potential | Node potentials: Mat(size: nStates x 1; type: CV_32FC1). This parameter should be preinitialized and set to value 0. |
[in,out] | mask | Relevant Node potentials: Mat(size: nStates x 1; type: CV_8UC1). This parameter should be preinitialized and set to value 1 (all potentials are relevant). |
Implements DirectGraphicalModels::CTrainNode.
Definition at line 267 of file TrainNodeGMM.cpp.
|
protectedvirtual |
Loads the random model from the file.
Allows to re-use the class.
pFile | Pointer to the file, opened for reading. |
Implements DirectGraphicalModels::CBaseRandomModel.
Definition at line 228 of file TrainNodeGMM.cpp.
|
virtual |
Resets class variables.
Allows to re-use the class.
Implements DirectGraphicalModels::CBaseRandomModel.
Definition at line 38 of file TrainNodeGMM.cpp.
|
protectedvirtual |
Saves the random model into the file.
Allows to re-use the class.
pFile | Pointer to the file, opened for writing. |
Implements DirectGraphicalModels::CBaseRandomModel.
Definition at line 196 of file TrainNodeGMM.cpp.
|
virtual |
Random model training.
Auxilary function for training - some derived classes may use this function inbetween training and classification phases
doClean | Flag indicating if the memory, keeping the trining data should be released after training |
Reimplemented from DirectGraphicalModels::CTrainNode.
Definition at line 154 of file TrainNodeGMM.cpp.
|
private |
Definition at line 88 of file TrainNodeGMM.h.
|
private |
Definition at line 86 of file TrainNodeGMM.h.
|
private |
Definition at line 87 of file TrainNodeGMM.h.
|
staticprivate |
Definition at line 82 of file TrainNodeGMM.h.
|
staticprivate |
Definition at line 81 of file TrainNodeGMM.h.