importNetworkFromONNX did not recognize softmax layer
Hello,
I am using importNetworkFromONNX to import a neural network exported from pyTorch.
The network includes a softmax layer. (onnx_model.onnx file is attached as a zip file.)
Below picture shows the model’s netron view:
However, when I imported the onnx model, MATLAB did not recognize the softmax layer.
I know that I can relace the layer with MATLAB’s Softmax layer.
But, I want to know how to import the onnx model without replacing the layer.
Below is the code I used to import the onnx model.
clear
modelfile = "onnx_model.onnx";
localNet = importNetworkFromONNX(modelfile, InputDataFormats=’BC’);
InputSize = [4 1];
X = dlarray(rand(InputSize),"CB");
localNet = initialize(localNet, X);
localNet = expandLayers(localNet);
localNet.Layers
The results was:
>> test_import_onnx
ans =
9×1 Layer array with layers:
1 ‘onnx__Gemm_0’ Feature Input 4 features
2 ‘onnx__Gemm_0_BatchSizeVerifier’ Verify the fixed batch size Verify the fixed batch size of 1
3 ‘x_fc1_pi_Gemm’ Fully Connected 5 fully connected layer
4 ‘x_Relu’ ReLU ReLU
5 ‘x_fc2_pi_Gemm’ Fully Connected 2 fully connected layer
6 ‘SoftmaxLayer1003’ onnx_model.SoftmaxLayer1003 onnx_model.SoftmaxLayer1003
7 ‘x_fc1_v_Gemm’ Fully Connected 1 fully connected layer
8 ‘x11Output’ Custom output (‘CB’) See the OutputInformation property to find the output dimension ordering that is produced by this layer.
9 ‘x12Output’ Custom output (‘CB’) See the OutputInformation property to find the output dimension ordering that is produced by this layer.
Because onnx_model.SoftmaxLayer1003 did not work as a softmax layer, the outputs of SoftmaxLayer1003 were always [1; 1].Hello,
I am using importNetworkFromONNX to import a neural network exported from pyTorch.
The network includes a softmax layer. (onnx_model.onnx file is attached as a zip file.)
Below picture shows the model’s netron view:
However, when I imported the onnx model, MATLAB did not recognize the softmax layer.
I know that I can relace the layer with MATLAB’s Softmax layer.
But, I want to know how to import the onnx model without replacing the layer.
Below is the code I used to import the onnx model.
clear
modelfile = "onnx_model.onnx";
localNet = importNetworkFromONNX(modelfile, InputDataFormats=’BC’);
InputSize = [4 1];
X = dlarray(rand(InputSize),"CB");
localNet = initialize(localNet, X);
localNet = expandLayers(localNet);
localNet.Layers
The results was:
>> test_import_onnx
ans =
9×1 Layer array with layers:
1 ‘onnx__Gemm_0’ Feature Input 4 features
2 ‘onnx__Gemm_0_BatchSizeVerifier’ Verify the fixed batch size Verify the fixed batch size of 1
3 ‘x_fc1_pi_Gemm’ Fully Connected 5 fully connected layer
4 ‘x_Relu’ ReLU ReLU
5 ‘x_fc2_pi_Gemm’ Fully Connected 2 fully connected layer
6 ‘SoftmaxLayer1003’ onnx_model.SoftmaxLayer1003 onnx_model.SoftmaxLayer1003
7 ‘x_fc1_v_Gemm’ Fully Connected 1 fully connected layer
8 ‘x11Output’ Custom output (‘CB’) See the OutputInformation property to find the output dimension ordering that is produced by this layer.
9 ‘x12Output’ Custom output (‘CB’) See the OutputInformation property to find the output dimension ordering that is produced by this layer.
Because onnx_model.SoftmaxLayer1003 did not work as a softmax layer, the outputs of SoftmaxLayer1003 were always [1; 1]. Hello,
I am using importNetworkFromONNX to import a neural network exported from pyTorch.
The network includes a softmax layer. (onnx_model.onnx file is attached as a zip file.)
Below picture shows the model’s netron view:
However, when I imported the onnx model, MATLAB did not recognize the softmax layer.
I know that I can relace the layer with MATLAB’s Softmax layer.
But, I want to know how to import the onnx model without replacing the layer.
Below is the code I used to import the onnx model.
clear
modelfile = "onnx_model.onnx";
localNet = importNetworkFromONNX(modelfile, InputDataFormats=’BC’);
InputSize = [4 1];
X = dlarray(rand(InputSize),"CB");
localNet = initialize(localNet, X);
localNet = expandLayers(localNet);
localNet.Layers
The results was:
>> test_import_onnx
ans =
9×1 Layer array with layers:
1 ‘onnx__Gemm_0’ Feature Input 4 features
2 ‘onnx__Gemm_0_BatchSizeVerifier’ Verify the fixed batch size Verify the fixed batch size of 1
3 ‘x_fc1_pi_Gemm’ Fully Connected 5 fully connected layer
4 ‘x_Relu’ ReLU ReLU
5 ‘x_fc2_pi_Gemm’ Fully Connected 2 fully connected layer
6 ‘SoftmaxLayer1003’ onnx_model.SoftmaxLayer1003 onnx_model.SoftmaxLayer1003
7 ‘x_fc1_v_Gemm’ Fully Connected 1 fully connected layer
8 ‘x11Output’ Custom output (‘CB’) See the OutputInformation property to find the output dimension ordering that is produced by this layer.
9 ‘x12Output’ Custom output (‘CB’) See the OutputInformation property to find the output dimension ordering that is produced by this layer.
Because onnx_model.SoftmaxLayer1003 did not work as a softmax layer, the outputs of SoftmaxLayer1003 were always [1; 1]. importnetworkfromonnx, deep learning toolbox, onnx MATLAB Answers — New Questions