MATLAB Answers

trainNetwork invalid network

226 views (last 30 days)
Why am I getting an invalid network error from trainNetwork? It says layers are not connected and that the input layer is not first and the output layer is not last. I am resuming functionality of my network following the directions in the link below. When I visualize my layers, they are all connected properly and the first layer is the input layer and the last is the output. Why am I getting these errors?
Error using trainNetwork (line 154)
Invalid network.
Caused by:
Layer 'L1': Missing input. Each layer input must be connected to the
output of another layer.
Layer 'L3': Missing input. Each layer input must be connected to the
output of another layer.
Detected missing inputs:
input 'in2'
Layer 'L7': Unused output. Each layer output must be connected to the
input of another layer.
Layer 'L0': An input layer must be first in the layer array.
Layer 'Lend': An output layer must be last in the layer array.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Jul 2018
This error is due to a DAGNetwork object being inputted into the trainNetwork for the layers. The correct workflow is to use a Layer array or a LayerGraph object as input to trainNetwork:
To fix the issue, convert the DAGNetwork object into a LayerGraph object first before training:
>> newnet = trainNetwork(source, layerGraph(net),options);
The layer graph describes the architecture of a DAG network (layers and connections). Net.Layers is missing the connections causing those errors.


MatlabUserN on 13 Feb 2019
I am trying to use transfer learning technique to use LayerGraph. But somehow getting this error how to resolve it
Error using nnet.internal.cnn.util.validateLayersForLayerGraph>iAssertUniqueAndNonEmptyLayerNames (line 62)
Layer names in layer array must be nonempty.
Zarrin Wu
Zarrin Wu on 24 Apr 2019
You should give a name to all layers when calling layerGraph function.

Sign in to comment.

More Answers (1)

blue cat
blue cat on 20 Jun 2019
Edited: blue cat on 20 Jun 2019
I tried "layerGraph(net)", but I still meet "Error using trainNetwork ; Invalid network; Layer '...': Unused input...." problem. How can I solve it?
Below is my code:
NET = shufflenet;NET.Layers;backbone = NET.Layers(1:170);
net = trainNetwork(tbtrain,layerGraph(layers),options);


SARAH LONER on 29 Nov 2019
hai sir did u slove the error at trainNetwork?
i also had the same error for image segmentation using unet
can u help me to clear this error
Mohammad Bhat
Mohammad Bhat on 24 Jan 2020
lgraph = layerGraph(layers);
where layers is your netwrok/architecture
net = trainNetwork(trainingData,lgraph ,opts);
It will solve yoyur problem. It solved mine also

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!