Direct Graphical Models
v.1.7.0
|
Base abstract class for node potentials training. More...
#include <TrainNode.h>
Public Member Functions | |
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... | |
virtual void | addFeatureVec (const Mat &featureVector, byte gt)=0 |
Adds new feature vector. More... | |
virtual void | train (bool doClean=false) |
Random model training. 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 | reset (void)=0 |
Resets class variables. More... | |
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... | |
Static Public Member Functions | |
static std::shared_ptr< CTrainNode > | create (byte nodeRandomModel, byte nStates, word nFeatures) |
Factory method returning node trainer object. More... | |
Protected Member Functions | |
virtual void | calculateNodePotentials (const Mat &featureVector, Mat &potential, Mat &mask) const =0 |
Calculates the node potential, based on the feature vector. More... | |
Protected Member Functions inherited from DirectGraphicalModels::CBaseRandomModel | |
virtual void | saveFile (FILE *pFile) const =0 |
Saves the random model into the file. More... | |
virtual void | loadFile (FILE *pFile)=0 |
Loads the random model from the file. More... | |
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 | |
Mat | m_mask |
Additional Inherited Members | |
Protected Attributes inherited from DirectGraphicalModels::CBaseRandomModel | |
byte | m_nStates |
The number of states (classes) More... | |
Base abstract class for node potentials training.
The common usage for node potentials training is as follow:
See Demo Train for more details
Definition at line 47 of file TrainNode.h.
|
inline |
Constructor.
nStates | Number of states (classes) |
nFeatures | Number of features |
Definition at line 55 of file TrainNode.h.
|
virtualdefault |
|
pure 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) |
Implemented in DirectGraphicalModels::CTrainNodeMsRF, DirectGraphicalModels::CTrainNodeCvRF, DirectGraphicalModels::CTrainNodeCvANN, DirectGraphicalModels::CTrainNodeCvGMM, DirectGraphicalModels::CTrainNodeCvSVM, DirectGraphicalModels::CTrainNodeKNN, DirectGraphicalModels::CTrainNodeGMM, DirectGraphicalModels::CTrainNodeCvKNN, and DirectGraphicalModels::CTrainNodeBayes.
void DirectGraphicalModels::CTrainNode::addFeatureVecs | ( | const Mat & | featureVectors, |
const Mat & | gt | ||
) |
Adds a block of new feature vectors.
Used to add multiple featureVectors, corresponding to the ground-truth states (classes) gt for training
featureVectors | Multi-channel matrix, each element of which is a multi-dimensinal point: Mat(type: CV_8UC(nFeatures)) |
gt | Matrix, each element of which is a ground-truth state (class) |
Definition at line 42 of file TrainNode.cpp.
void DirectGraphicalModels::CTrainNode::addFeatureVecs | ( | const vec_mat_t & | featureVectors, |
const Mat & | gt | ||
) |
Adds a block of new feature vectors.
Used to add multiple featureVectors, corresponding to the ground-truth states (classes) gt for training
featureVectors | Vector of size nFeatures, each element of which is a single feature - image: Mat(type: CV_8UC1) |
gt | Matrix, each element of which is a ground-truth state (class) |
Definition at line 48 of file TrainNode.cpp.
|
protectedpure virtual |
Calculates the node potential, based on the feature vector.
This function calculates the potentials of the node, described with the sample featureVector, being in each state (belonging to each class). These potentials are united in the node potential vector:
\[nodePot[nStates] = f(\textbf{f}[nFeatures]).\]
Functions \( f \) must be implemented in derived classes.
[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). |
Implemented in DirectGraphicalModels::CTrainNodeMsRF, DirectGraphicalModels::CTrainNodeCvRF, DirectGraphicalModels::CTrainNodeGMM, DirectGraphicalModels::CTrainNodeCvANN, DirectGraphicalModels::CTrainNodeCvGMM, DirectGraphicalModels::CTrainNodeCvSVM, DirectGraphicalModels::CTrainNodeBayes, DirectGraphicalModels::CTrainNodeKNN, and DirectGraphicalModels::CTrainNodeCvKNN.
|
static |
Factory method returning node trainer object.
nodeRandomModel | Type of desired random model (Ref. NodeRandomModel) |
nStates | Number of states (classes) |
nFeatures | Number of features |
Definition at line 20 of file TrainNode.cpp.
Mat DirectGraphicalModels::CTrainNode::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.
featureVectors | Multi-channel matrix, each element of which is a multi-dimensinal point: Mat(type: CV_8UC(nFeatures)) |
weights | The block of weighting parameters Mat(type: CV_32FC1). If empty, values 1 are used. |
Z | The value of partition function. In order to convert potential to the probability, it is multiplied by \(1/Z\). If \(Z\leq0\), the resulting node potentials are normalized to 100, independently for each potential. |
Definition at line 54 of file TrainNode.cpp.
Mat DirectGraphicalModels::CTrainNode::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.
featureVectors | Vector of size nFeatures, each element of which is a single feature - image: Mat(type: CV_8UC1) |
weights | The block of weighting parameter Mat(type: CV_32FC1) |
Z | The value of partition function. In order to convert potential to the probability, it is multiplied by \(1/Z\). If \(Z\leq0\), the resulting node potentials are normalized to 100, independently for each potential. |
Definition at line 91 of file TrainNode.cpp.
Mat DirectGraphicalModels::CTrainNode::getNodePotentials | ( | const Mat & | featureVector, |
float | weight, | ||
float | Z = 0.0f |
||
) | const |
Returns the node potential, based on the feature vector.
This function calls calculateNodePotentials() function, which should be implemented in derived classes. After that, the resulting node potential is powered by parameter weight.
featureVector | Multi-dimensinal point \(\textbf{f}\): Mat(size: nFeatures x 1; type: CV_{XX}C1) |
weight | The weighting parameter (default value is 1) |
Z | The value of partition function. In order to convert potential to the probability, it is multiplied by \(1/Z\). If \(Z\leq0\), the resulting node potentials are normalized to 100, independently for every function call. |
Definition at line 129 of file TrainNode.cpp.
|
inlinevirtual |
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 |
Implements DirectGraphicalModels::ITrain.
Reimplemented in DirectGraphicalModels::CTrainNodeMsRF, DirectGraphicalModels::CTrainNodeCvRF, DirectGraphicalModels::CTrainNodeCvANN, DirectGraphicalModels::CTrainNodeCvGMM, DirectGraphicalModels::CTrainNodeCvSVM, DirectGraphicalModels::CTrainNodeKNN, DirectGraphicalModels::CTrainNodeCvKNN, DirectGraphicalModels::CTrainNodeGMM, and DirectGraphicalModels::CTrainNodeBayes.
Definition at line 92 of file TrainNode.h.
|
private |
Definition at line 139 of file TrainNode.h.