123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /**
- * @file SemSegContextTree.h
- * @brief Context Trees -> Combination of decision tree and context information
- * @author Björn Fröhlich
- * @date 29.11.2011
- */
- #ifndef SemSegContextTreeINCLUDE
- #define SemSegContextTreeINCLUDE
- #include "SemanticSegmentation.h"
- #include <objrec/math/mathbase/VVector.h>
- #include "objrec/features/localfeatures/LFColorWeijer.h"
- namespace OBJREC {
- /** Localization system */
- class SemSegContextTree : public SemanticSegmentation
- {
- protected:
-
- class Node
- {
- public:
- /** probabilities for each class */
- vector<double> probs;
-
- /** left child node */
- int left;
-
- /** right child node */
- int right;
-
- /** position of feat for decision */
- int feat;
-
- /** decision stamp */
- double decision;
-
- /** is the node a leaf or not */
- bool isleaf;
-
- /** distribution in current node */
- vector<double> dist;
-
- /** depth of the node in the tree */
- int depth;
-
- /** simple constructor */
- Node():left(-1),right(-1),feat(-1), decision(-1.0), isleaf(false){}
-
- /** standard constructor */
- Node(int _left, int _right, int _feat, double _decision):left(_left),right(_right),feat(_feat), decision(_decision),isleaf(false){}
- };
-
- /** store features */
- VVector currentfeats;
-
- /** store the positions of the features */
- VVector positions;
-
- /** tree -> saved as vector of nodes */
- vector<Node> tree;
-
- /** local features */
- LFColorWeijer *lfcw;
-
- /** distance between features */
- int grid;
-
- /** maximum samples for tree */
- int maxSamples;
-
- /** count samples per label */
- map<int,int> labelcounter;
-
- /** map of labels */
- map<int,int> labelmap;
-
- /** map of labels inverse*/
- map<int,int> labelmapback;
-
- /** scalefactor for balancing for each class */
- vector<double> a;
-
- /** the minimum number of features allowed in a leaf */
- int minFeats;
-
- /** maximal depth of tree */
- int maxDepth;
-
- public:
- /** simple constructor */
- SemSegContextTree( const Config *conf, const MultiDataset *md );
-
- /** simple destructor */
- virtual ~SemSegContextTree();
- /**
- * test a single image
- * @param ce input data
- * @param segresult segmentation results
- * @param probabilities probabilities for each pixel
- */
- void semanticseg ( CachedExample *ce, NICE::Image & segresult, GenericImage<double> & probabilities );
-
- /**
- * the main training method
- * @param md training data
- */
- void train ( const MultiDataset *md );
-
- /**
- * compute best split for current settings
- * @param feats features
- * @param currentfeats matrix with current node for each feature
- * @param labels labels for each feature
- * @param node current node
- * @param splitfeat output feature position
- * @param splitval
- */
- void getBestSplit(const vector<vector<vector<vector<double> > > > &feats, vector<vector<vector<int> > > ¤tfeats,const vector<vector<vector<int> > > &labels, int node, int &splitfeat, double &splitval);
- };
- } // namespace
- #endif
|