Direct Graphical Models  v.1.7.0
DirectGraphicalModels::CTrainLinkNested< Trainer > Class Template Reference

Nested link (inter-layer edge) training class. More...

#include <TrainLinkNested.h>

Inheritance diagram for DirectGraphicalModels::CTrainLinkNested< Trainer >:
Collaboration diagram for DirectGraphicalModels::CTrainLinkNested< Trainer >:

Public Member Functions

 CTrainLinkNested (byte nStatesBase, byte nStatesOccl, word nFeatures)
 Constructor. More...
 
template<class TrainerParams >
 CTrainLinkNested (byte nStatesBase, byte nStatesOccl, word nFeatures, TrainerParams params)
 Constructor. More...
 
virtual ~CTrainLinkNested (void)
 
virtual void reset (void)
 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...
 
virtual void addFeatureVec (const Mat &featureVector, byte gtb, byte gto)
 Adds a feature vector. More...
 
virtual void train (bool doClean=false)
 Random model training. More...
 
- Public Member Functions inherited from DirectGraphicalModels::CTrainLink
 CTrainLink (byte nStatesBase, byte nStatesOccl, word nFeatures)
 Constructor. More...
 
virtual ~CTrainLink (void)=default
 
void addFeatureVec (const Mat &featureVectors, const Mat &gtb, const Mat &gto)
 Adds a block of new feature vectors. More...
 
void addFeatureVec (const vec_mat_t &featureVectors, const Mat &gtb, const Mat &gto)
 Adds a block of new feature vectors. More...
 
Mat getLinkPotentials (const Mat &featureVector, float weight=1.0f) const
 Returns the link 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)
 
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 calculateLinkPotentials (const Mat &featureVector) const
 Returns the data-dependent link (inter-layer 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

CPriorNodem_pPrior
 Node prior poobability More...
 
CTrainNodem_pTrainer
 Node trainer More...
 

Additional Inherited Members

- Protected Attributes inherited from DirectGraphicalModels::CTrainLink
byte m_nStatesBase
 Number of states (classes) at the base layer of ML-CRF. More...
 
byte m_nStatesOccl
 Number of states (classes) at the occlusion layerts of ML-CRF. More...
 
- Protected Attributes inherited from DirectGraphicalModels::CBaseRandomModel
byte m_nStates
 The number of states (classes) More...
 

Detailed Description

template<class Trainer>
class DirectGraphicalModels::CTrainLinkNested< Trainer >

Nested link (inter-layer edge) training class.

This class in order to estimate edge potentials, uses an unary potential trainer, which is learned for nStatesBase \(\times\) nStatesOccl states (classes), corresponding to the base and occlusion layers of the graphical model.

Template Parameters
TrainerThe nested node potential trainer, derived from the CTrainNode class
Author
Sergey G. Kosov, serge.nosp@m.y.ko.nosp@m.sov@p.nosp@m.roje.nosp@m.ct-10.nosp@m..de

Definition at line 21 of file TrainLinkNested.h.

Constructor & Destructor Documentation

◆ CTrainLinkNested() [1/2]

template<class Trainer >
DirectGraphicalModels::CTrainLinkNested< Trainer >::CTrainLinkNested ( byte  nStatesBase,
byte  nStatesOccl,
word  nFeatures 
)
inline

Constructor.

Parameters
nStatesBaseNumber of states (classes) for the base layer of the graphical model
nStatesOcclNumber of states (classes) for the occlusion layer of the graphical model

nStatesBase * nStatesOccl must be less then 256.

nFeaturesNumber of features

Definition at line 31 of file TrainLinkNested.h.

◆ CTrainLinkNested() [2/2]

template<class Trainer >
template<class TrainerParams >
DirectGraphicalModels::CTrainLinkNested< Trainer >::CTrainLinkNested ( byte  nStatesBase,
byte  nStatesOccl,
word  nFeatures,
TrainerParams  params 
)
inline

Constructor.

Template Parameters
TrainerParamsType of the parameters to the nested node potential trainer
Parameters
nStatesBaseNumber of states (classes) for the base layer of the graphical model
nStatesOcclNumber of states (classes) for the occlusion layer of the graphical model
nFeaturesNumber of features
paramsParameters of the nested node potential trainer

Definition at line 48 of file TrainLinkNested.h.

◆ ~CTrainLinkNested()

template<class Trainer >
virtual DirectGraphicalModels::CTrainLinkNested< Trainer >::~CTrainLinkNested ( void  )
inlinevirtual

Definition at line 58 of file TrainLinkNested.h.

Member Function Documentation

◆ addFeatureVec()

template<class Trainer >
virtual void DirectGraphicalModels::CTrainLinkNested< Trainer >::addFeatureVec ( const Mat &  featureVector,
byte  gtb,
byte  gto 
)
inlinevirtual

Adds a feature vector.

Used to add featureVector, corresponding to the ground-truth states (classes) gtb and gto for training. Here the couple {gtb, gto} corresponds to the nodes from base aod occlusion layers.

Parameters
featureVectorMulti-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to both nodes of the link.
gtbThe ground-truth state (class) of the first node of the edge, corresponding to the base layer
gtoThe ground-truth state (class) of the second node of the edge, corresponding to the occlusion layer

Implements DirectGraphicalModels::CTrainLink.

Definition at line 68 of file TrainLinkNested.h.

Here is the call graph for this function:

◆ calculateLinkPotentials()

template<class Trainer >
virtual Mat DirectGraphicalModels::CTrainLinkNested< Trainer >::calculateLinkPotentials ( const Mat &  featureVector) const
inlineprotectedvirtual

Returns the data-dependent link (inter-layer edge) potentials.

This function returns edge potential matrix, which elements are obrained from the unary potential vector:

\[ edgePot[nStatesBase:nStates][0:nStatesBase] = nodePot[nStatesBase \times nStatesOccl] = f(\textbf{f}[nFeatures]). \]

Here \( nStates = nStatesBase + nStatesOccl\).

Parameters
featureVectorMulti-dimensinal point \(\textbf{f}\): Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the data site of the both edge nodes
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implements DirectGraphicalModels::CTrainLink.

Definition at line 100 of file TrainLinkNested.h.

Here is the call graph for this function:

◆ load()

template<class Trainer >
virtual void DirectGraphicalModels::CTrainLinkNested< Trainer >::load ( const std::string &  path,
const std::string &  name = std::string(),
short  idx = -1 
)
inlinevirtual

Loads the training data.

Allows to re-use the class. Loads data to the file: "<path><name>_<idx>.dat".

Parameters
pathPath to the folder, containing the data file.
nameName of data file. If empty, will be generated automatically from the class name.
idxIndex of the data file. Negative value means no index.

Reimplemented from DirectGraphicalModels::CBaseRandomModel.

Definition at line 66 of file TrainLinkNested.h.

Here is the call graph for this function:

◆ loadFile()

template<class Trainer >
virtual void DirectGraphicalModels::CTrainLinkNested< Trainer >::loadFile ( FILE *  pFile)
inlineprotectedvirtual

Loads the random model from the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for reading.

Implements DirectGraphicalModels::CBaseRandomModel.

Definition at line 91 of file TrainLinkNested.h.

◆ reset()

template<class Trainer >
virtual void DirectGraphicalModels::CTrainLinkNested< Trainer >::reset ( void  )
inlinevirtual

Resets class variables.

Allows to re-use the class.

Implements DirectGraphicalModels::CBaseRandomModel.

Definition at line 64 of file TrainLinkNested.h.

Here is the call graph for this function:

◆ save()

template<class Trainer >
virtual void DirectGraphicalModels::CTrainLinkNested< Trainer >::save ( const std::string &  path,
const std::string &  name = std::string(),
short  idx = -1 
) const
inlinevirtual

Saves the training data.

Allows to re-use the class. Stores data to the file: "<path><name>_<idx>.dat".

Parameters
pathPath to the destination folder.
nameName of data file. If empty, will be generated automatically from the class name.
idxIndex of the destination file. Negative value means no index.

Reimplemented from DirectGraphicalModels::CBaseRandomModel.

Definition at line 65 of file TrainLinkNested.h.

Here is the call graph for this function:

◆ saveFile()

template<class Trainer >
virtual void DirectGraphicalModels::CTrainLinkNested< Trainer >::saveFile ( FILE *  pFile) const
inlineprotectedvirtual

Saves the random model into the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for writing.

Implements DirectGraphicalModels::CBaseRandomModel.

Definition at line 90 of file TrainLinkNested.h.

◆ train()

template<class Trainer >
virtual void DirectGraphicalModels::CTrainLinkNested< Trainer >::train ( bool  doClean = false)
inlinevirtual

Random model training.

Auxilary function for training - some derived classes may use this function inbetween training and classification phases

Note
This function must be called inbetween the training and classification phases
Parameters
doCleanFlag indicating if the memory, keeping the trining data should be released after training

Reimplemented from DirectGraphicalModels::CTrainLink.

Definition at line 75 of file TrainLinkNested.h.

Here is the call graph for this function:

Member Data Documentation

◆ m_pPrior

template<class Trainer >
CPriorNode* DirectGraphicalModels::CTrainLinkNested< Trainer >::m_pPrior
private

Node prior poobability

Definition at line 124 of file TrainLinkNested.h.

◆ m_pTrainer

template<class Trainer >
CTrainNode* DirectGraphicalModels::CTrainLinkNested< Trainer >::m_pTrainer
private

Node trainer

Definition at line 125 of file TrainLinkNested.h.


The documentation for this class was generated from the following file: