MATLAB: TrainNetwork invalid network

connectionDeep Learning ToolboxerrorlayernetNetworkneuralresumetraining

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.

Best Answer

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.
Related Question