error using importONNXNetwork, importONNXNetwork cannot be called from compiled applications.

I used importONNXNetwork in MATLAB R2023b to load a .onnx file, then converted it into a DLL using MATLAB Compiler, and called it under Win64 through Visual Studio 2019. However, when running, I encountered an error: "Error using importONNXNetwork. importONNXNetwork cannot be called from compiled applications." What could be the issue?

 Réponse acceptée

The issue is that you are not permitted to call importONNXNetwork in a compiled application.
You have to break the code into two pieces. The first piece is not to be compiled; it loads the required network, trains it, and saves the trained network into a .mat file. The second piece is to be compiled; it loads the trained network from the .mat file and uses it to predict() or classify()
In compiled applications, you are limited to loading a trained network and using the trained network. Compiled applications cannot import networks or manipulate the layers or train networks.

4 commentaires

You need to load the onnxnet in code that is not compiled, and save it as a .mat file, and load the .mat file in the code that is compiled.
Thanks Bro.
I did saved the .onnx file as a .mat file and successfully loaded it with load().net to obtain a DAGNetwork in the MATLAB code and it ran correctly. Then After compiling the whole function(include net = load('xxx.mat').net ) into a DLL and calling it from a C++ console program, the following warning and error were displayed:
'Warning: The variable 'net' originally saved as a DAGNetwork could not be instantiated as an object and will be read in as uint32.
>Location: FunctionName (line 20)
Warning: Data sample time is assumed to be 1 second. To specify a different value for the data sample time, consider providing data using a timetable or an iddata object.
>Location: idpack.iodata.extractRefDataFromAnalysisInputList>localDeduceSampling (line 412)
>Location: idpack.iodata.extractRefDataFromAnalysisInputList (line 108) Location: idmodel.parseCompareResidPredictInputs (line 66)
>Location: predict (line 83)
> Location: FunctionName (line 43)
Error using predict The number of inputs and outputs of the model must match that of the data.'
What's going on here? Is there a problem with a detail?"
You need to add
%#function DAGNetwork
as a comment in the code to be deployed.
Thank you, brother, you are a genius.The problem is solved! ^_^

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by