8 #include "FeaturesConcatenator.h" 38 DGM_ASSERT(nStates < 16);
39 m_pPrior = std::make_unique<CPriorNode>(nStates * nStates);
40 m_pTrainer = std::make_unique<Trainer>(nStates * nStates, nFeatures);
52 template<
class TrainerParams>
CTrainEdgeConcat(byte nStates, word nFeatures, TrainerParams params)
56 DGM_ASSERT(nStates < 16);
57 m_pPrior = std::make_unique<CPriorNode>(nStates * nStates);
58 m_pTrainer = std::make_unique<Trainer>(nStates * nStates, nFeatures, params);
66 void save(
const std::string &path,
const std::string &name = std::string(),
short idx = -1)
const {
m_pTrainer->save(path, name.empty() ?
"CTrainEdgeConcat" : name, idx); }
67 void load(
const std::string &path,
const std::string &name = std::string(),
short idx = -1) {
m_pTrainer->load(path, name.empty() ?
"CTrainEdgeConcat" : name, idx); }
69 virtual void addFeatureVecs(
const Mat &featureVector1, byte gt1,
const Mat &featureVector2, byte gt2)
80 DllExport
virtual void saveFile(FILE *pFile)
const {}
81 DllExport
virtual void loadFile(FILE *pFile) {}
94 DllExport
virtual Mat
calculateEdgePotentials(
const Mat &featureVector1,
const Mat &featureVector2,
const vec_float_t &vParams)
const 96 const float nodePotWeight = 1.0f;
103 for (byte gt1 = 0; gt1 <
m_nStates; gt1++) {
104 float * pRes = res.ptr<
float>(gt1);
105 for (byte gt2 = 0; gt2 <
m_nStates; gt2++) {
108 float epsilon = prior.at<
float>(gt) > 0 ? FLT_EPSILON : 0.0f;
109 pRes[gt2] = MAX(pot.at<
float>(gt), epsilon);
virtual ~CTrainEdgeConcat(void)=default
virtual void train(bool doClean=false)
Random model training.
void save(const std::string &path, const std::string &name=std::string(), short idx=-1) const
Saves the training data.
virtual Mat calculateEdgePotentials(const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const
Returns the data-dependent edge potentials.
void load(const std::string &path, const std::string &name=std::string(), short idx=-1)
Loads the training data.
CTrainEdgeConcat(byte nStates, word nFeatures)
Constructor.
Base abstract class for edge potentials training.
Base abstract class for random model training.
virtual void reset(void)
Resets class variables.
Concatenated edge training class.
virtual void saveFile(FILE *pFile) const
Saves the random model into the file.
CTrainEdgeConcat(byte nStates, word nFeatures, TrainerParams params)
Constructor.
virtual void loadFile(FILE *pFile)
Loads the random model from the file.
virtual void addFeatureVecs(const Mat &featureVector1, byte gt1, const Mat &featureVector2, byte gt2)
Adds a pair of feature vectors.
std::unique_ptr< CFeaturesConcatenator > m_pConcatenator
Feature concatenator.
std::unique_ptr< CTrainNode > m_pTrainer
Node trainer
Mat m_featureVector
Feature vector.
byte m_nStates
The number of states (classes)
std::unique_ptr< CPriorNode > m_pPrior
Node prior poobability