"Constant" Error when loading in model using loadLearnerForCoder()

On a project at work, we are trying to convert a ML model to C++ using the MATLAB coder. We have done it sucessfully before but now something has gone wrong. In MATLAB Coder, when it runs the error check, it complains the function call for loadLearnerForCoder fails b/c "The Model must be a compiler-time constant". For the sake of a testing, I regenerated a smaller model (b/c our last one took a whole day to generate). When I load it in the same way, it gives no errors. When comparing the two models in MATLAB I can't really see an issue. Does anyone know how to debug this better or see what MATLAB is erroring out on? Also I cannot provide any code for this due to work. I've tried using coder.constant() and it doesn't work. I also used coder.screener() and it reported no problems.

4 件のコメント

Walter Roberson
Walter Roberson 2025 年 2 月 28 日
Roughly speaking, that error would be generated if you had something of the form
model_name = "YourModelNameGoesHere";
do_the_compile_stuff(model_name)
when instead you need
do_the_compile_stuff("YourModelNameGoesHere")
Joshua
Joshua 2025 年 2 月 28 日
The code is currently written roughly like this:
function [x,y] = predictFuntion(input) %#codegen
mdlPath = "path\to\model";
mdl = loadLearnerForCoder(mdlPath)
[x,y] = predict(mdl, input);
end
This works for one model but not the other. Would what you stated still be the case and I should just try it as one line instead of two?
Walter Roberson
Walter Roberson 2025 年 2 月 28 日
Try it as one line.
Joshua
Joshua 2025 年 3 月 3 日
Unfortunately that did not work.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGenerating Code についてさらに検索

製品

リリース

R2024b

質問済み:

2025 年 2 月 28 日

コメント済み:

2025 年 3 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by