Direct Graphical Models
v.1.7.0
|
Base abstract class for edge potentials training. More...
#include <TrainEdge.h>
Public Member Functions | |
CTrainEdge (byte nStates, word nFeatures) | |
Constructor. More... | |
virtual | ~CTrainEdge (void)=default |
virtual void | addFeatureVecs (const Mat &featureVector1, byte gt1, const Mat &featureVector2, byte gt2)=0 |
Adds a pair of feature vectors. More... | |
virtual void | train (bool doClean=false) |
Random model training. More... | |
Mat | getEdgePotentials (const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams, float weight=1.0f) const |
Returns the edge potential, based on the feature vectors. 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< CTrainEdge > | create (byte edgeRandomModel, byte nStates, word nFeatures) |
Factory method returning edge trainer object. More... | |
static Mat | getDefaultEdgePotentials (float val, byte nStates) |
Returns the data-independent edge potentials. More... | |
static Mat | getDefaultEdgePotentials (const vec_float_t &values) |
Returns the data-independent edge potentials. More... | |
Protected Member Functions | |
virtual Mat | calculateEdgePotentials (const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const =0 |
Calculates the edge potential, based on the feature vectors. 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... | |
Additional Inherited Members | |
Protected Attributes inherited from DirectGraphicalModels::CBaseRandomModel | |
byte | m_nStates |
The number of states (classes) More... | |
Base abstract class for edge potentials training.
Refer to the Demo Train for the application and common usage example
Definition at line 24 of file TrainEdge.h.
|
inline |
Constructor.
nStates | Number of states (classes) |
nFeatures | Number of features |
Definition at line 32 of file TrainEdge.h.
|
virtualdefault |
|
pure virtual |
Adds a pair of feature vectors.
Used to add featureVector1 and featureVector2, corresponding to the ground-truth states (classes) gt1 and gt2 for training. Here the couple {featureVector1, gt1} corresponds to the first node of the edge, and the couple {featureVector2, gt2} - to the second node.
featureVector1 | Multi-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the first node of the edge. |
gt1 | The ground-truth state (class) of the first node of the edge, given by featureVector1 |
featureVector2 | Multi-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the second node of the edge. |
gt2 | The ground-truth state (class) of the second node of the edge, given by featureVector2 |
Implemented in DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >, DirectGraphicalModels::CTrainEdgePotts, and DirectGraphicalModels::CTrainEdgePrior.
|
protectedpure virtual |
Calculates the edge potential, based on the feature vectors.
This function calculates the potentials of an edge, described with two samples featureVector1 and featureVector2, correspondig to the both nodes defining that edge. The resulting potentials of the two nodes being in each possible state (belonging to each possible class) at the same time, are united in the edge potential matrix:
\[edgePot[nStates][nStates] = f(\textbf{f}_1[nFeatures],\textbf{f}_2[nFeatures]).\]
Functions \( f \) must be implemented in derived classes.
featureVector1 | Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the first node of the edge |
featureVector2 | Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the second node of the edge |
vParams | Array of control parameters. Please refere to the concrete model implementation of the calculateEdgePotentials() function for more details |
Implemented in DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >, DirectGraphicalModels::CTrainEdgePottsCS, DirectGraphicalModels::CTrainEdgePrior, and DirectGraphicalModels::CTrainEdgePotts.
|
static |
Factory method returning edge trainer object.
edgeRandomModel | Type of desired random model (Ref. EdgeRandomModel) |
nStates | Number of states (classes) |
nFeatures | Number of features |
Definition at line 16 of file TrainEdge.cpp.
|
inlinestatic |
Returns the data-independent edge potentials.
This function returns matrix with diagonal elements equal to the argument val, all the other elements are 1's, what imitates the Potts model.
\[edgePot[nStates][nStates] = \begin{bmatrix} val & 1 & \cdots & 1 \\ 1 & val & \cdots & 1 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 1 & \cdots & val \end{bmatrix} \]
val | The diagonal element of the matrix |
nStates | Number of states (classes) |
Definition at line 74 of file TrainEdge.h.
|
static |
Returns the data-independent edge potentials.
This function returns matrix with diagonal elements specified by argument array values, all the other elements are 1's, what imitates the Potts model.
\[edgePot[nStates][nStates] = \begin{bmatrix} values_1 & 1 & \cdots & 1 \\ 1 & values_2 & \cdots & 1 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 1 & \cdots & values_{nStates} \end{bmatrix} \]
values | The array of diagonal elements of the matrix. In must include nStates values, specifying smoothness strength for each state (class) individually. |
Definition at line 47 of file TrainEdge.cpp.
Mat DirectGraphicalModels::CTrainEdge::getEdgePotentials | ( | const Mat & | featureVector1, |
const Mat & | featureVector2, | ||
const vec_float_t & | vParams, | ||
float | weight = 1.0f |
||
) | const |
Returns the edge potential, based on the feature vectors.
This function calls calculateEdgePotentials() function, which should be implemented in derived classes. After that, the resulting edge potential is powered by parameter weight.
featureVector1 | Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the first node of the edge |
featureVector2 | Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the second node of the edge |
vParams | Array of control parameters. Please refer to the concrete model implementation of the calculateEdgePotentials() function for more details |
weight | The weighting parameter |
Definition at line 29 of file TrainEdge.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::CTrainEdgeConcat< Trainer, Concatenator >, and DirectGraphicalModels::CTrainEdgePrior.
Definition at line 54 of file TrainEdge.h.