Ask Your Question
0

How do I access the class_labels stored in OpenCV ML RF XML file?

asked 2017-09-02 08:31:42 -0500

Phil C gravatar image

I need to know what class_labels are in my trained model when loaded from XML. I cannot see how to access them from the XML, where they are clearly stored as a numerical list \<<class_labels> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24<\class_labels>> in my saved XML.

There are no methods for reading such from a model.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-09-04 02:01:09 -0500

berak gravatar image

updated 2017-09-04 02:02:30 -0500

you can use opencv's FileStorage to inspect the saved xml file.

i don't have a serialized RF xml file at hand, but for an SVM it is:

<?xml version="1.0"?>
<opencv_storage>
<opencv_ml_svm> // 1st level
  ...
  <class_labels type_id="opencv-matrix"> // 2nd level
    <rows>5</rows>
    <cols>1</cols>
    <dt>i</dt>
    <data>
      1 2 3 4 5</data></class_labels>
  ...

FileStorage fs("my.xml", FileStorage::READ);
Mat labels;
fs["opencv_ml_svm"]["class_labels"] >> labels;  // change tag names to your need !

cerr << labels.t() << endl;
//[1,2,3,4,5]
edit flag offensive delete link more

Comments

Thanks! Obvious really. But I was uncertain about then pulling the rest of the model into the RF.

Phil C gravatar imagePhil C ( 2017-09-25 08:08:46 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-02 08:31:42 -0500

Seen: 1,337 times

Last updated: Sep 04 '17