![]() |
Direct Graphical Models
v.1.7.0
|
Microsoft Sherwood Random Forest training class. More...
#include <TrainNodeMsRF.h>
Public Member Functions | |
CTrainNodeMsRF (byte nStates, word nFeatures, TrainNodeMsRFParams params=TRAIN_NODE_MS_RF_PARAMS_DEFAULT) | |
Constructor. More... | |
CTrainNodeMsRF (byte nStates, word nFeatures, size_t maxSamples) | |
Constructor. More... | |
virtual | ~CTrainNodeMsRF (void) |
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... | |
void | addFeatureVec (const Mat &featureVector, byte gt) |
Adds new feature vector. More... | |
void | train (bool doClean=false) |
Random model training. More... | |
![]() | |
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... | |
![]() | |
ITrain (byte nStates, word nFeatures) | |
Constructor. More... | |
virtual | ~ITrain (void)=default |
word | getNumFeatures (void) const |
Returns number of features. More... | |
![]() | |
CBaseRandomModel (byte nStates) | |
Constructor. More... | |
virtual | ~CBaseRandomModel (void) |
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... | |
![]() | |
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 Member Functions | |
void | init (TrainNodeMsRFParams params) |
Private Attributes | |
std::unique_ptr< sw::Forest< sw::LinearFeatureResponse, sw::HistogramAggregator > > | m_pRF |
Random Forest classifier. More... | |
std::unique_ptr< CSamplesAccumulator > | m_pSamplesAcc |
Samples Accumulator. More... | |
std::unique_ptr< sw::TrainingParameters > | m_pParams |
Additional Inherited Members | |
![]() | |
static std::shared_ptr< CTrainNode > | create (byte nodeRandomModel, byte nStates, word nFeatures) |
Factory method returning node trainer object. More... | |
![]() | |
byte | m_nStates |
The number of states (classes) More... | |
Microsoft Sherwood Random Forest training class.
This class is based on the Sherwood C++ code library for decision forests v.1.0.0
In order to use the Sherwood library, DGM must be built with the USE_SHERWOOD flag
Definition at line 52 of file TrainNodeMsRF.h.
DirectGraphicalModels::CTrainNodeMsRF::CTrainNodeMsRF | ( | byte | nStates, |
word | nFeatures, | ||
TrainNodeMsRFParams | params = TRAIN_NODE_MS_RF_PARAMS_DEFAULT |
||
) |
Constructor.
nStates | Number of states (classes) |
nFeatures | Number of features |
params | Random Forest parameters (Ref. TrainNodeMsRFParams) |
Definition at line 19 of file TrainNodeMsRF.cpp.
DirectGraphicalModels::CTrainNodeMsRF::CTrainNodeMsRF | ( | byte | nStates, |
word | nFeatures, | ||
size_t | maxSamples | ||
) |
Constructor.
nStates | Number of states (classes) |
nFeatures | Number of features |
maxSamples | Maximum number of samples to be used in training.
|
Definition at line 25 of file TrainNodeMsRF.cpp.
|
virtual |
Definition at line 45 of file TrainNodeMsRF.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 66 of file TrainNodeMsRF.cpp.
|
protectedvirtual |
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). |
Implements DirectGraphicalModels::CTrainNode.
Definition at line 109 of file TrainNodeMsRF.cpp.
|
private |
|
virtual |
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 60 of file TrainNodeMsRF.cpp.
|
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 90 of file TrainNodeMsRF.h.
|
virtual |
Resets class variables.
Allows to re-use the class
Implements DirectGraphicalModels::CBaseRandomModel.
Definition at line 48 of file TrainNodeMsRF.cpp.
|
virtual |
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 54 of file TrainNodeMsRF.cpp.
|
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 89 of file TrainNodeMsRF.h.
|
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 71 of file TrainNodeMsRF.cpp.
|
private |
Definition at line 101 of file TrainNodeMsRF.h.
|
private |
Random Forest classifier.
Definition at line 99 of file TrainNodeMsRF.h.
|
private |
Samples Accumulator.
Definition at line 100 of file TrainNodeMsRF.h.