DLnetwork definition and training problem with outputLayer
조회 수: 22 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Abhinav Aravindan
2024년 5월 8일
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
Lucas García
2024년 5월 11일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!