Skip to content

class_labels vector in boosted decision tree classifier is empty when saved and then loaded from disk #5412

@afriesen

Description

@afriesen

OpenCV 3.0 seems to use a new format for writing the boosted decision tree classifier to disk, but tries to support the older format as well. When loading a file from disk, it first reads in the value of a FileNode "format" and uses this to determine whether the classifier was written using the old or the new method (the exact check is bool isLegacy = format < 3;). However, although OpenCV 3.0 writes to disk using the new format, it does not specify a "format" FileNode; thus, when the classifier is subsequently read from disk, it incorrectly thinks that it was written in the legacy format.

A simple fix for this is to add the following line to DTreesImpl::writeParams(FileStorage& fs) in tree.cpp.

void DTreesImpl::writeParams(FileStorage& fs) const
{
    // ---- begin new code ---- 
    fs << "format" << (int) 3;
    // ---- end new code ---- 
    fs << "is_classifier" << isClassifier();
    ...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions