Error using trainNetwork. Invalid network.

net = googlenet('Weights','none');
lys = net.Layers;
lys(end-3:end)
numClasses = numel(categories(imdsTrain.Labels));
lgraph = layerGraph(lys);
%Replace the classification layers for new task
newFCLayer = fullyConnectedLayer(3,'Name','new_fc','WeightLearnRateFactor',10,'BiasLearnRateFactor',10);
lgraph = replaceLayer(lgraph,'loss3-classifier',newFCLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'output',newClassLayer);
analyzeNetwork(lgraph)
%Resize the image
imageSize=net.Layers(1).InputSize;
augmentedTrainingSet=augmentedImageDatastore(imageSize,...
imdsTrain,'ColorPreprocessing','gray2rgb');
augmentedValidateSet=augmentedImageDatastore(imageSize,...
imdsValidation,'ColorPreprocessing','gray2rgb');
options = trainingOptions('sgdm', ...
'MiniBatchSize',4, ...
'MaxEpochs',8, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',augmentedValidateSet, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'ExecutionEnvironment','cpu', ...
'Plots','training-progress');
trainedNet = trainNetwork(augmentedTrainingSet,lgraph,options);
ERROR:
Error using trainNetwork
Invalid network.
Caused by:
Layer 'inception_3a-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_3b-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4a-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4b-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4c-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4d-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4e-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_5a-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_5b-output': Unconnected input. Each layer input must be connected to the output of another
layer.

답변 (2개)

Sugandhi
Sugandhi 2023년 5월 14일

0 개 추천

Hi Tan,
I understand that you are facing error using trainNetwork.
The error message indicates that there are unconnected inputs in the network. Specifically, the error message indicates that the input layers of some of the intermediate layers in the network graph are not connected to any output layers. This can commonly occur if you remove layers from the network and do not update the graph accordingly.
To fix the error, you should check the layer graph for any unconnected layers. You can do this using the `analyzeNetwork` function:
analyzeNetwork(lgraph)
This function will display a graph of the layers in your network and highlight any unconnected nodes.
You can then use the `connectLayers` function to connect the unconnected layers to the output of the preceding layers. For example, to connect the `inception_3a-output` layer to the `inception_3a/5x5_reduce` layer, you can use the following code:
lgraph = connectLayers(lgraph,'inception_3a/output','inception_3a/5x5_reduce');
Repeat this step for any other unconnected layers in the network. After you have connected all the layers, you can try training the network again.
Note that if you have removed or modified any layers in the original network, you may need to make additional modifications to the layer graph to ensure that the network is properly connected.

댓글 수: 5

Tan
Tan 2023년 5월 14일
> lgraph = connectLayers(lgraph,'inception_3a-output','inception_3a-5x5_reduce');
Error using nnet.cnn.LayerGraph>iValidateEndLayerInputIsNotOccupied
Unable to connect to 'inception_3a-5x5_reduce'. This input is already connected.
Error in nnet.cnn.LayerGraph/connectLayers (line 310)
iValidateEndLayerInputIsNotOccupied( ..
Sugandhi
Sugandhi 2023년 5월 14일
> lgraph = connectLayers(lgraph,'inception_3a-output','inception_3a-5x5_reduce');
Above code is just an example, you should connect unconnected inputs in the network to any output.The error says that 'inception_3a-5x5_reduce' is already connected.
Tan
Tan 2023년 5월 20일
Tan
Tan 2023년 5월 20일
it shows that inception_3a output. unconnected input.
Tan
Tan 2023년 5월 20일
while i connect it with the previous layer it want me to specify connect to which input

댓글을 달려면 로그인하십시오.

kalai
kalai 2024년 10월 13일

0 개 추천

Training with trainNetwork failed.
Invalid network:
Layer 'conv1': Invalid input data. The number of channels of the input data (1) must match the layer's expected number of channels (3)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

Tan
2023년 5월 14일

답변:

2024년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by