exporting weights and parameters from matlab to c++

354 views Asked by At

I used the tree bagger function to create a random forest model for obtained trained classifier.

Used function:

 %Create a Random Forest model with 100 trees,
  randomfmodel = TreeBagger(...............)

Is there a way I could export the model values generated directly ( in form of values and weights ) so that it can be used on a c++ platform.

i read that the matlab runtime is large and basically that is the reason why I want to use the generated weights and parameters from matlab model and then export it and write a code for testing new data in c++ I am trying to avoid rewriting the code in C++ for training . (Using the model values from matlab will help me directly test on new data.)

I do have a randomfmodel.mat file in matlab . Is there a way I could export all the weights so that I could rewrite a function in c++ to use it for testing new data?

1

There are 1 answers

0
WolfgangG On

I haven't tried it myself but found the following. The description of the files promise exactly what you are looking for: https://github.com/kenders2000/decisionTreeMat2Cpp

https://github.com/dhasenfratz/TreeBagger-Matlab2Cpp

This program takes a decision tree trained in Matlab using TreeBagger or the classification tree function ClassificationTree and outputs the header file decTreeConstants.h containing all the branch information. This header file is used by the attached C++ class to make decisions based on presented features in deployed applications.

This is useful for deploying code developed in Matlab into embedded applications where Matlab is not available and no input files can be read.