Direct Graphical Models  v.1.7.0
DirectGraphicalModels::CTrainNodeCvSVM Class Reference

OpenCV Support Vector Machines training class. More...

#include <TrainNodeCvSVM.h>

Inheritance diagram for DirectGraphicalModels::CTrainNodeCvSVM:
Collaboration diagram for DirectGraphicalModels::CTrainNodeCvSVM:

Public Member Functions

 CTrainNodeCvSVM (byte nStates, word nFeatures, TrainNodeCvSVMParams params=TRAIN_NODE_CV_SVM_PARAMS_DEFAULT)
 Constructor. More...
 
 CTrainNodeCvSVM (byte nStates, word nFeatures, size_t maxSamples)
 Constructor. More...
 
virtual ~CTrainNodeCvSVM (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...
 
- Public Member Functions inherited from DirectGraphicalModels::CTrainNode
 CTrainNode (byte nStates, word nFeatures)
 Constructor. More...
 
virtual ~CTrainNode (void)=default
 
void addFeatureVecs (const Mat &featureVectors, const Mat &gt)
 Adds a block of new feature vectors. More...
 
void addFeatureVecs (const vec_mat_t &featureVectors, const Mat &gt)
 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...
 
- 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

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...
 
- 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...
 

Protected Attributes

Ptr< ml::SVM > m_pSVM
 Support Vector Machine. More...
 
CSamplesAccumulatorm_pSamplesAcc
 Samples Accumulator. More...
 
- Protected Attributes inherited from DirectGraphicalModels::CBaseRandomModel
byte m_nStates
 The number of states (classes) More...
 

Private Member Functions

void init (TrainNodeCvSVMParams params)
 

Additional Inherited Members

- Static Public Member Functions inherited from DirectGraphicalModels::CTrainNode
static std::shared_ptr< CTrainNodecreate (byte nodeRandomModel, byte nStates, word nFeatures)
 Factory method returning node trainer object. More...
 

Detailed Description

OpenCV Support Vector Machines training class.

This class implements the Support vector machine classifier (SVM).

Note
This trainer was not well-tested.
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 39 of file TrainNodeCvSVM.h.

Constructor & Destructor Documentation

◆ CTrainNodeCvSVM() [1/2]

DirectGraphicalModels::CTrainNodeCvSVM::CTrainNodeCvSVM ( byte  nStates,
word  nFeatures,
TrainNodeCvSVMParams  params = TRAIN_NODE_CV_SVM_PARAMS_DEFAULT 
)

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features
paramsSVM parameters (Ref. TrainNodeCvSVMParams)

Definition at line 7 of file TrainNodeCvSVM.cpp.

Here is the call graph for this function:

◆ CTrainNodeCvSVM() [2/2]

DirectGraphicalModels::CTrainNodeCvSVM::CTrainNodeCvSVM ( byte  nStates,
word  nFeatures,
size_t  maxSamples 
)

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features
maxSamplesMaximum number of samples to be used in training

Default value 0 means using all the samples.
If another value is specified, the class for training will use maxSamples random samples from the whole amount of samples, added via addFeatureVec() function

Definition at line 13 of file TrainNodeCvSVM.cpp.

Here is the call graph for this function:

◆ ~CTrainNodeCvSVM()

DirectGraphicalModels::CTrainNodeCvSVM::~CTrainNodeCvSVM ( void  )
virtual

Definition at line 31 of file TrainNodeCvSVM.cpp.

Member Function Documentation

◆ addFeatureVec()

void DirectGraphicalModels::CTrainNodeCvSVM::addFeatureVec ( const Mat &  featureVector,
byte  gt 
)
virtual

Adds new feature vector.

Used to add a featureVector, corresponding to the ground-truth state (class) gt for training

Parameters
featureVectorMulti-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1)
gtCorresponding ground-truth state (class)

Implements DirectGraphicalModels::CTrainNode.

Definition at line 54 of file TrainNodeCvSVM.cpp.

Here is the call graph for this function:

◆ calculateNodePotentials()

void DirectGraphicalModels::CTrainNodeCvSVM::calculateNodePotentials ( const Mat &  featureVector,
Mat &  potential,
Mat &  mask 
) const
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.

Parameters
[in]featureVectorMulti-dimensinal point \(\textbf{f}\): Mat(size: nFeatures x 1; type: CV_{XX}C1)
[in,out]potentialNode potentials: Mat(size: nStates x 1; type: CV_32FC1). This parameter should be preinitialized and set to value 0.
[in,out]maskRelevant 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 80 of file TrainNodeCvSVM.cpp.

◆ init()

void DirectGraphicalModels::CTrainNodeCvSVM::init ( TrainNodeCvSVMParams  params)
private

Definition at line 20 of file TrainNodeCvSVM.cpp.

Here is the caller graph for this function:

◆ load()

void DirectGraphicalModels::CTrainNodeCvSVM::load ( const std::string &  path,
const std::string &  name = std::string(),
short  idx = -1 
)
virtual

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 48 of file TrainNodeCvSVM.cpp.

Here is the call graph for this function:

◆ loadFile()

void DirectGraphicalModels::CTrainNodeCvSVM::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 70 of file TrainNodeCvSVM.h.

◆ reset()

void DirectGraphicalModels::CTrainNodeCvSVM::reset ( void  )
virtual

Resets class variables.

Allows to re-use the class.

Implements DirectGraphicalModels::CBaseRandomModel.

Definition at line 36 of file TrainNodeCvSVM.cpp.

Here is the call graph for this function:

◆ save()

void DirectGraphicalModels::CTrainNodeCvSVM::save ( const std::string &  path,
const std::string &  name = std::string(),
short  idx = -1 
) const
virtual

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 42 of file TrainNodeCvSVM.cpp.

Here is the call graph for this function:

◆ saveFile()

void DirectGraphicalModels::CTrainNodeCvSVM::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 69 of file TrainNodeCvSVM.h.

◆ train()

void DirectGraphicalModels::CTrainNodeCvSVM::train ( bool  doClean = false)
virtual

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::CTrainNode.

Definition at line 59 of file TrainNodeCvSVM.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_pSamplesAcc

CSamplesAccumulator* DirectGraphicalModels::CTrainNodeCvSVM::m_pSamplesAcc
protected

Samples Accumulator.

Definition at line 80 of file TrainNodeCvSVM.h.

◆ m_pSVM

Ptr<ml::SVM> DirectGraphicalModels::CTrainNodeCvSVM::m_pSVM
protected

Support Vector Machine.

Definition at line 79 of file TrainNodeCvSVM.h.


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