exportONNXNetwork works but importONNXNetwork can't load input layer

9 次查看(过去 30 天)
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 个评论
Luke Hubbard
Luke Hubbard 2023-2-23
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?

请先登录,再进行评论。

回答(1 个)

Tamir Suliman
Tamir Suliman 2023-2-23
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 个评论
Luke Hubbard
Luke Hubbard 2023-2-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by