Direct Graphical Models
v.1.7.0
|
Concatenated edge training class. More...
#include <TrainEdgeConcat.h>
Public Member Functions | |
CTrainEdgeConcat (byte nStates, word nFeatures) | |
Constructor. More... | |
template<class TrainerParams > | |
CTrainEdgeConcat (byte nStates, word nFeatures, TrainerParams params) | |
Constructor. More... | |
virtual | ~CTrainEdgeConcat (void)=default |
virtual void | reset (void) |
Resets class variables. More... | |
void | save (const std::string &path, const std::string &name=std::string(), short idx=-1) const |
Saves the training data. More... | |
void | load (const std::string &path, const std::string &name=std::string(), short idx=-1) |
Loads the training data. More... | |
virtual void | addFeatureVecs (const Mat &featureVector1, byte gt1, const Mat &featureVector2, byte gt2) |
Adds a pair of feature vectors. More... | |
virtual void | train (bool doClean=false) |
Random model training. More... | |
Public Member Functions inherited from DirectGraphicalModels::CTrainEdge | |
CTrainEdge (byte nStates, word nFeatures) | |
Constructor. More... | |
virtual | ~CTrainEdge (void)=default |
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) |
byte | getNumStates (void) const |
Returns number of states (classes) More... | |
Protected Member Functions | |
virtual void | saveFile (FILE *pFile) const |
Saves the random model into the file. More... | |
virtual void | loadFile (FILE *pFile) |
Loads the random model from the file. More... | |
virtual Mat | calculateEdgePotentials (const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const |
Returns the data-dependent edge potentials. 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 | |
std::unique_ptr< CPriorNode > | m_pPrior |
Node prior poobability More... | |
std::unique_ptr< CTrainNode > | m_pTrainer |
Node trainer More... | |
std::unique_ptr< CFeaturesConcatenator > | m_pConcatenator |
Feature concatenator. More... | |
Mat | m_featureVector |
Feature vector. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from DirectGraphicalModels::CTrainEdge | |
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 Attributes inherited from DirectGraphicalModels::CBaseRandomModel | |
byte | m_nStates |
The number of states (classes) More... | |
Concatenated edge training class.
This class in order to estimate edge potentials, uses an unary potential trainer, which is learned for \(nStates^2\) states (classes). Both edge feature vectors are concatenated in one feature vector, which in its turn, is used for the unary potential trainer. The feature concatenation is performed by the CFeaturesConcatenator class.
Trainer | The nested node potential trainer, derived from the CTrainNode class |
Concatenator | The feature concatenator, derived from the CFeaturesConcatenator class |
Definition at line 25 of file TrainEdgeConcat.h.
|
inline |
Constructor.
nStates | Number of states (classes)
|
nFeatures | Number of features |
Definition at line 34 of file TrainEdgeConcat.h.
|
inline |
Constructor.
TrainerParams | Type of the parameters to the nested node potential trainer |
nStates | Number of states (classes)
|
nFeatures | Number of features |
params | Parameters of the nested node potential trainer |
Definition at line 52 of file TrainEdgeConcat.h.
|
virtualdefault |
|
inlinevirtual |
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 |
Implements DirectGraphicalModels::CTrainEdge.
Definition at line 69 of file TrainEdgeConcat.h.
|
inlineprotectedvirtual |
Returns the data-dependent edge potentials.
This function returns edge potential matrix, which elements are obrained from the unary potential vector:
\[ edgePot[nStates][nStates] = nodePot[nStates^2] = f(concat(\textbf{f}_1[nFeatures],\textbf{f}_2[nFeatures])). \]
The resulting edge potential matrix is normalized such that its largest element is equal to paramter \(\theta\), and then regularized as follows:
\[ edgePot_{s,s} = \left\{\begin{array}{ll} 1 &\mbox{ if $edgePot_{s,s}<1$} \\ edgePot_{s,s} &\mbox{ otherwise}\end{array} \right.\;\;\;\forall s\in\mathbb{S}.\]
featureVector1 | Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the first node of the edge |
featureVector2 | Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the second node of the edge |
vParams | Array of control parameters \(\vec{\theta}\), which must consist from one parameter, specifying the largest value in the resulting edge potential. |
Implements DirectGraphicalModels::CTrainEdge.
Definition at line 94 of file TrainEdgeConcat.h.
|
inlinevirtual |
Loads the training data.
Allows to re-use the class. Loads data to the file: "<path><name>_<idx>.dat".
path | Path to the folder, containing the data file. |
name | Name of data file. If empty, will be generated automatically from the class name. |
idx | Index of the data file. Negative value means no index. |
Reimplemented from DirectGraphicalModels::CBaseRandomModel.
Definition at line 67 of file TrainEdgeConcat.h.
|
inlineprotectedvirtual |
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 81 of file TrainEdgeConcat.h.
|
inlinevirtual |
Resets class variables.
Allows to re-use the class.
Implements DirectGraphicalModels::CBaseRandomModel.
Definition at line 65 of file TrainEdgeConcat.h.
|
inlinevirtual |
Saves the training data.
Allows to re-use the class. Stores data to the file: "<path><name>_<idx>.dat".
path | Path to the destination folder. |
name | Name of data file. If empty, will be generated automatically from the class name. |
idx | Index of the destination file. Negative value means no index. |
Reimplemented from DirectGraphicalModels::CBaseRandomModel.
Definition at line 66 of file TrainEdgeConcat.h.
|
inlineprotectedvirtual |
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 80 of file TrainEdgeConcat.h.
|
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 |
Reimplemented from DirectGraphicalModels::CTrainEdge.
Definition at line 76 of file TrainEdgeConcat.h.
|
private |
Feature vector.
Definition at line 121 of file TrainEdgeConcat.h.
|
private |
Feature concatenator.
Definition at line 120 of file TrainEdgeConcat.h.
|
private |
Node prior poobability
Definition at line 118 of file TrainEdgeConcat.h.
|
private |
Node trainer
Definition at line 119 of file TrainEdgeConcat.h.