【发布时间】:2016-06-08 23:50:41
【问题描述】:
我正在从 30000 个随机生成的特征中学习一棵增强树。学习仅限于说最好的 100 个特征。在学习了如何从 CvBoost 对象中提取决策树使用的特征的索引之后。
我这样做的动机是消除生成所有 30000 个特征的要求,并且只计算将使用的那些特征。我已经包含了从 CvBoost.save 函数生成的 yml 文件的打印输出。我想我想要的是名为 sample_count 的值,它在深度 1 的决策树中标识如下所示的特征:
trees:
-
best_tree_idx: -1
nodes:
-
depth: 0
sample_count: 11556
value: -1.8339875099775065e+00
norm_class_idx: 0
Tn: 0
complexity: 0
alpha: 0.
node_risk: 0.
tree_risk: 0.
tree_error: 0.
splits:
- { var:497, quality:8.6223608255386353e-01,
le:5.3123302459716797e+00 }
-
depth: 1
sample_count: 10702
value: -1.8339875099775065e+00
norm_class_idx: 0
Tn: 0
complexity: 0
alpha: 0.
node_risk: 0.
tree_risk: 0.
tree_error: 0.
-
depth: 1
sample_count: 854
value: 1.8339875099775065e+00
norm_class_idx: 1
Tn: 0
complexity: 0
alpha: 0.
node_risk: 0.
tree_risk: 0.
tree_error: 0.
编辑
目前我有以下用于访问数据的代码:
//Interrogate the Decision Tree. Each element is a Decision Tree, making up the classifer
CvSeq* decisionTree = boostDevice.get_weak_predictors();
simplifyFeatureSet(decisionTree, firstOrderROIs );
这个函数是:
inline void Chnftrs::simplifyFeatureSet(CvSeq* decisionTree, std::vector<boost::tuple<int, cv::Rect> >& rois)
{
//This variable stores the index of the feature used from rois and a pointer to the split so that the variable there can
//be updated when the rois are pruned and reordered.
std::vector<boost::tuple<int, CvDTreeSplit* > > featureIdx;
//Determine the max depth of the tree
printf("Size of boost %d \n", decisionTree->total);
for (int i = 0; i < decisionTree->total; i++)
{
//Get the root of the tree
CvBoostTree *tree =0;
tree = (CvBoostTree*)cvGetSeqElem(decisionTree, i);
if(tree == 0)
printf("Tree is NULL\n");
else
printf("Tree Addr %ld\n", tree);
const CvDTreeNode *root = tree->get_root();
printf("Class_idx %d, Value %f ", root->sample_count, root->value);
featureIdx.push_back(boost::tuple<int, CvDTreeSplit*>(root->split->var_idx, root->split));
//Search down the right hand side
depthFirstSearch(root->right, featureIdx);
//Search down the left hand side
depthFirstSearch(root->left, featureIdx);
}
}
但是,当我尝试访问 root 的任何成员(例如 root->sample_count)时,我遇到了分段错误。除非 CvTreeTrainData.shared 设置为 true(默认情况下为 false),否则 CvTree 的成员可能无法访问。如图所示here
任何帮助都会很棒
干杯
彼得
【问题讨论】:
标签: opencv machine-learning decision-tree adaboost