memory error when compiling fitcensemble model using coder

2 ビュー (過去 30 日間)
Christian Meyer
Christian Meyer 2020 年 8 月 3 日
コメント済み: Raunak Gupta 2020 年 8 月 8 日
Hello,
I am trying to increase the speed of a random forest machine learning model I have trained in Matlab using the "fitcensemble" method by compiling it to C code. However, when I use the Coder app, the memory during the "Generating Trial Code" step continues to grow until Matlab crashes. I have 64GB of RAM while the model file size is 92MB so hardware is unlikely the problem. (Model could not be included due to file size restrictions).
I have attached a zip file with the project which recapitulates the error.
Briefly,
I first fit the model
t = templateTree('MinLeafSize',2);
Mdl = fitcensemble(train,train_lab,'Learners',t,'Method','Bag','Learners',t,'CrossVal','on','NumLearningCycles',50);
Where train is a 2D array with 18 feature columns and train_lab is a 1D array with labels (3 classes).
Next I save the best model from the cross-validation for the coder
saveLearnerForCoder(Mdl.Trained{7},'072920_bagged50Tree')
Then I generate two scripts (both in zip file)
myBagEnsemblePredict.m
function [label,score] = myBagEnsemblePredict(X,fileName) %#codegen
CompactMdl = loadLearnerForCoder(fileName);
[label,score] = predict(CompactMdl,X);
end
and
test_myBagEnsemblePredict.m
load('test_data_coder.mat')
[label,score] = myBagEnsemblePredict(test,'072920_bagged50Tree');
These are used as input for the Coder app.
When I start the coder App, I specify "myBagEnsemblePredict" as the entry-point function
My input types are autodefined from test_myBagEnsemblePredict.m
and edited as above
When I generate the code, the memory increases over time until matlab crashes.
Here are my memory settings in the coder
The complete configuration is in the attached zip file ("coder_settings.mat")
Other potentially relevant information:
Running Matlab 2020a on a 64-bit Linux machine (Ubuntu). I have tried changing the X variable to have the size (double(:100X18)) and observed the same memory error. I have tried shrinking the model by using "MaxNumSplit" option in the fitcensemble step. I have tried reducing the Dynamic memory allocation threshold to 1000.
Thank you in advance for your time and help.
  1 件のコメント
Raunak Gupta
Raunak Gupta 2020 年 8 月 8 日
Hi Christian,
I don't see the trained model file 072920_bagged50Tree.mat in the code_reproduce_error folder. It will be really helpful if you attach that too, for reproducing the error at my end.
I also assume you are following this documentation for carrying out the implementation.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCode Generation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by