How can i correctly an ONNX file into MATLAB?

7 views (last 30 days)
Gema Rincon
Gema Rincon on 8 Nov 2022
Answered: Sanjana on 31 Oct 2023
I have imported my ONNX network with the importONNXLayer function, because in the description of the neural network there are 5 operators that are not supported by the MAtlab operators list. I have followed the steps in the documentation to replace the layers to avoid those operators that it does not recognize but i do not get a good result.
It seems to matter but when doing the analysis the errors still appear and the network is not similar to the one i see in ONNX, i attach images to see the comparision. Also i do not know how to solve the problem of importing the number of entries, i attach image:
(Input error)
(ONNX Network)
(Imported ONNX Network)
Also, this ONNX is trained as a reinforcement learning network and I am not convinced to replace certain layers by others. Is there any other way to solve the issue of operadoes?
Attached code:
modelfile="last_FrankaCabinet_ep_1500_rew_1874.9808.onnx";
%lgraph=importONNXNetwork(modelfile)
lgraph=importONNXLayers(modelfile,TargetNetwork="dagnetwork")
lgraph.Layers
%lgraph_layer=importONNXFunction(modelfile,"shufflenltFcn")
%% plot(lgraph_layer)
% Ejemplo para las layers con Placeholder openExample('onnxconverter/ImportONNXModelAsLayerGraphWithPlaceholderLayersExample')
placeholders= findPlaceholderLayers(lgraph)
InputLayer1 = classificationLayer('Name','obs');
outputLayer2 = classificationLayer('Name','OutputLayer_advantages');
outputLayer3 = classificationLayer('Name','OutputLayer_returns');
outputLayer4 = classificationLayer('Name','OutputLayer_actions');
outputLayer5 = classificationLayer('Name','OutputLayer_mu');
outputLayer6 = classificationLayer('Name','OutputLayer_sigma');
%lgraph = replaceLayer(lgraph,'obs',InputLayer1);
lgraph = replaceLayer(lgraph,'OutputLayer_advantages',outputLayer2);
lgraph = replaceLayer(lgraph,'OutputLayer_returns',outputLayer3);
lgraph = replaceLayer(lgraph,'OutputLayer_actions',outputLayer4);
lgraph = replaceLayer(lgraph,'OutputLayer_mu',outputLayer5);
lgraph = replaceLayer(lgraph,'OutputLayer_sigma',outputLayer6);
lgraph.Layers
plot(lgraph);
analyzeNetwork(lgraph)

Answers (1)

Sanjana
Sanjana on 31 Oct 2023
Hi Gema,
I understand that you are trying to import “ONNX” network, with the “importONNXLayer” function and trying to replace placeholder layers with appropriate built-in layers.
From the network you shared, as per my understanding, I don’t think replacing the placeholder layers with “classificationLayers” is appropriate, as per the operators specified in the onnx network visualization. Whenever replacing placeholder layers, we need to replace the layers with built-in layers that has similar operations.
Please provide the “.onnx” file, to determine the appropriate solution based on the placeholderLayers obtained.
Hope this helps!

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!