DLnetwork definition and training problem with outputLayer
47 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I need to use dlnetwork (in order to export it to ONNX format).
I have defined its layers as follows:
layers = [
sequenceInputLayer(202,"Name","sequence")
fullyConnectedLayer(25,"Name","fc")
fullyConnectedLayer(2,"Name","fc_1")
softmaxLayer("Name","softmax")];
and then I defined the net:
nett = dlnetwork(layers);
so until here everything is fine.
When I am trying to train the network:
[net,tr] = trainNetwork(DATA,Alllabels, layers, options);
I get the following error:
Network: Missing output layer. The network must have at least one output layer.
Layer 'softmax': Unconnected output. Each layer output must be connected to the input of another
layer.
So I redefined my layers to include an ouput layer:
layers = [
sequenceInputLayer(202,"Name","sequence")
fullyConnectedLayer(25,"Name","fc")
fullyConnectedLayer(2,"Name","fc_1")
softmaxLayer("Name","softmax")
classificationLayer()];
but now the definition of the network as before (nett = dlnetwork(layers) ) returns the following error:
Layer 'classoutput': Detected output layer. The network must not have output layers.
So this is kind of a catch-22 problem - I need to add an output layer to train the network, but I must remove an output layer for defining it!!
Does someone have clue?
Thanks
0 Commenti
Risposte (2)
Abhinav Aravindan
il 8 Mag 2024
I understand that you are trying to train a deep learning network and export the trained network as an “ONNX” file but facing an issue in defining and training the network. While utilizing “dlnetwork”, the layers cannot contain an output layer.
The network input to “exportONNXNetwork” need not be a “dlnetwork” object. “layers” array can be utilized directly as an input to “trainNetwork” for training the neural network. The output of “trainNetwork” can then be exported as an “ONNX” file as given below. Kindly note that this is with respect to MATLAB R2023a.
% Define your network layers
layers = [
sequenceInputLayer(202,"Name","sequence")
fullyConnectedLayer(25,"Name","fc")
fullyConnectedLayer(2,"Name","fc_1")
softmaxLayer("Name","softmax")
classificationLayer()];
% Replace with your data and required training options
net = trainNetwork(data,layers,options);
% Export trained network as ONNX file
exportONNXNetwork(net, filename.onnx)
Please find below the documentation links for your reference.
exportONNXNetwork: https://www.mathworks.com/help/releases/R2023a/deeplearning/ref/exportonnxnetwork.html?s_tid=doc_ta#mw_844c3879-ae5e-4704-8595-20250a86a2ef
I hope this helps resolve your issue!
0 Commenti
Lucas García
il 11 Mag 2024
You should use the trainnet function instead of trainNetwork to train dlnetwork objects. That said, you can convert the Series or DAG network trained with trainNetwork if you are using R2024a by using dag2dlnetwork .
0 Commenti
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!