exportONNXNetwork works but importONNXNetwork can't load input layer

10 visualizzazioni (ultimi 30 giorni)
I'm training a sequence classification network with lstms similar to the ClassifySequenceDataUsingLSTMNetworksExample and then exporting the trained model as an ONNX model for use in python. I have found that if I train the model with XTrain being cells of sequences, the network that is produced
1-will export without complaint with exportONNXNetwork
2-will NOT import to python
3-will NOT import back into Matlab via importONNXNetwork. matlab complaint is "Unable to create an ouput layer for ONNX network output #1 ... because its data format is unkown or not supported as a MATLAB output layer. If you know the output format, pass it using the 'outputDataFormats' parameter."
To get the complaint in 3- I added the following in the example live script after line 45:
exportONNXNetwork(net,onnxFilename)
importONNXNetwork(onnxFilename)
The python loading error is similar to the matlab error in that the layer input tensor rank (similar to data format) is incorrect
I have successfully exported and imported a lstm network to/from onnx format. But in that case, I trained with a datastore vs in this example the training inputs are cell arrays. Don't understand why that would change the onnx export/import outcome.
  1 Commento
Luke Hubbard
Luke Hubbard il 23 Feb 2023
Looking at some previous examples where I was successfully able to export and import onnx models I noticed that the successful ones were all seriesNetworks while the ones I have trouble with are all DAGNetworks, and they were trained with R2021b vs R2022b. Maybe there's something going on there. What causes a network to be output as a seriesNetwork vs DAGNetwork?

Accedi per commentare.

Risposte (1)

Tamir Suliman
Tamir Suliman il 23 Feb 2023
All i can say based on your description, it seems like the issue may be related to the input data format or rank of the exported ONNX model, which is causing errors during the import process.
  1 Commento
Luke Hubbard
Luke Hubbard il 23 Feb 2023
Exactly what I think. Somehow, when the network is trained with in-memory data vs out-of-memory datastores, that property does not get set correctly somewhere during the export process. I would like to know if there's a property I can set in the trained network (in this case a DAGNetwork) so that the format of input/output layers is properly set in exportONNXNetwork.

Accedi per commentare.

Categorie

Scopri di più su Image Data Workflows in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by