123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /**
- * @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 <core/vector/VVector.h>
- #include "vislearning/features/localfeatures/LFColorWeijer.h"
- namespace OBJREC {
-
- class Operation;
-
- class TreeNode
- {
- public:
- /** probabilities for each class */
- std::vector<double> probs;
-
- /** left child node */
- int left;
-
- /** right child node */
- int right;
-
- /** position of feat for decision */
- Operation *feat;
-
- /** decision stamp */
- double decision;
-
- /** is the node a leaf or not */
- bool isleaf;
-
- /** distribution in current node */
- std::vector<double> dist;
-
- /** depth of the node in the tree */
- int depth;
-
- /** simple constructor */
- TreeNode():left(-1),right(-1),feat(NULL), decision(-1.0), isleaf(false){}
-
- /** standard constructor */
- TreeNode(int _left, int _right, Operation *_feat, double _decision):left(_left),right(_right),feat(_feat), decision(_decision),isleaf(false){}
- };
-
- class Operation
- {
- protected:
- int x1, y1, x2, y2, channel1, channel2;
- public:
- void set(int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2)
- {
- x1 = _x1;
- y1 = _y1;
- x2 = _x2;
- y2 = _y2;
- channel1 = _channel1;
- channel2 = _channel2;
- }
- /**
- * @brief abstract interface for feature computation
- * @param feats features
- * @param cfeats number of tree node for each pixel
- * @param tree current tree
- * @param x current x position
- * @param y current y position
- * @return double distance
- **/
- virtual double getVal(const NICE::MultiChannelImageT<double> &feats, const std::vector<std::vector<int> > &cfeats, const std::vector<TreeNode> &tree, const int &x, const int &y) = 0;
- virtual Operation* clone() = 0;
- virtual void writeInfos() = 0;
- };
-
- /** Localization system */
- class SemSegContextTree : public SemanticSegmentation
- {
- protected:
- /** tree -> saved as vector of nodes */
- std::vector<TreeNode> tree;
-
- /** local features */
- LFColorWeijer *lfcw;
-
- /** number of featuretype -> currently: local and context features = 2 */
- int ftypes;
-
- /** distance between features */
- int grid;
-
- /** maximum samples for tree */
- int maxSamples;
-
- /** size for neighbourhood */
- int windowSize;
-
- /** how many feats should be considered for a split */
- int featsPerSplit;
-
- /** count samples per label */
- std::map<int,int> labelcounter;
-
- /** map of labels */
- std::map<int,int> labelmap;
-
- /** map of labels inverse*/
- std::map<int,int> labelmapback;
-
- /** scalefactor for balancing for each class */
- std::vector<double> a;
-
- /** the minimum number of features allowed in a leaf */
- int minFeats;
-
- /** maximal depth of tree */
- int maxDepth;
-
- /** operations for pairwise features */
- std::vector<Operation*> ops;
-
- /** operations for pairwise context features */
- std::vector<Operation*> cops;
-
- /** vector of all possible features */
- std::vector<Operation*> featsel;
-
- /** use alternative calculation for information gain */
- bool useShannonEntropy;
-
- /** Classnames */
- ClassNames classnames;
- /** train selection */
- std::set<int> forbidden_classes;
-
- /** Configfile */
- const Config *conf;
-
- public:
- /** simple constructor */
- SemSegContextTree( const NICE::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, NICE::MultiChannelImageT<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 std::vector<MultiChannelImageT<double> > &feats, std::vector<std::vector<std::vector<int> > > ¤tfeats,const std::vector<std::vector<std::vector<int> > > &labels, int node, Operation *&splitfeat, double &splitval);
- };
- } // namespace
- #endif
|