Error Network: Missing output layer

34 vues (au cours des 30 derniers jours)
Fernando Bonilla Hidrobo
Fernando Bonilla Hidrobo le 27 Déc 2023
Modifié(e) : Matt J le 29 Déc 2023
I am creating an autoencoder where I want to use the Alexnet network for the encoder part (removing the last layers), and when I try to train the autoencoder, I get the error:
"Error using trainNetwork
Invalid network.
Caused by:
Network: Missing output layer. The network must have at least one output layer.
Layer 'output': Unconnected output. Each layer output must be connected to the input of another layer."
However, I do see the output layer of the decoder connected when I visualize the network graph before training.
Please, your help on how to solve the problem. Thank you.
  3 commentaires
Fernando Bonilla Hidrobo
Fernando Bonilla Hidrobo le 28 Déc 2023
Hi @Debraj Maji, this is the code of the autoencoder I am creating
alexNet = alexnet;
lgraph = layerGraph(alexNet.Layers(1:end-3)); % Remove the last three layers
bottleneckLayer = fullyConnectedLayer(256, 'Name', 'bottleneck');
lgraph2 = addLayers(lgraph, bottleneckLayer);
% Get the name of the last layer of the modified encoder
lastEncoderLayer = lgraph.Layers(end).Name;
lgraph2 = connectLayers(lgraph2, lastEncoderLayer, 'bottleneck');
classInput = imageInputLayer([1, 1, 4], 'Name', 'classInput', 'Normalization', 'none');
concatLayer = concatenationLayer(3, 2, 'Name', 'concat');
lgraph3 = addLayers(lgraph2, concatLayer);
lgraph4 = connectLayers(lgraph3, 'bottleneck', 'concat/in1');
lgraph5 = addLayers(lgraph4, classInput);
lgraph6 = connectLayers(lgraph5, 'classInput', 'concat/in2');
analyzeNetwork(lgraph8);
%% decoder
outputImageSize = [227, 227, 3];% (width x height x channels)
decoderLayers = [
transposedConv2dLayer(3, 64, 'Stride', 2, 'Cropping', 'same', 'Name', 'decoder_conv1')
reluLayer('Name', 'decoder_relu1')
transposedConv2dLayer(3, outputImageSize(3), 'Stride', 2, 'Cropping', 'same', 'Name', 'decoder_conv2')
];
outputLayer = convolution2dLayer(1, outputImageSize(3), 'Name', 'output');
lgraph7 = addLayers(lgraph6, decoderLayers);
lgraph8 = connectLayers(lgraph7, 'concat', 'decoder_conv1');
lgraph8 = addLayers(lgraph8, outputLayer);
lgraph8 = connectLayers(lgraph8, 'decoder_conv2', 'output');
analyzeNetwork(lgraph8);
%% Image Loading
datafolder = 'C:\Users\ferna\Desktop\U\10TH SEMESTER\MIC\IMAGES\FFT_2048\bicubic';
imds = imageDatastore(datafolder, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
[trainingData, validationData] = splitEachLabel(imds, 0.8, 'randomized');
options = trainingOptions('adam', ...
'MaxEpochs', 20, ...
'InitialLearnRate', 0.0001, ...
'ValidationData', validationData, ...
'Plots', 'training-progress');
autoencoder = trainNetwork(trainingData, lgraph8, options);
Cris LaPierre
Cris LaPierre le 28 Déc 2023
Déplacé(e) : Matt J le 28 Déc 2023
What do you want the output of your network to be? The output options can be viewed here:

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 28 Déc 2023
Modifié(e) : Matt J le 29 Déc 2023
The "output layer" referred to by the error message doesn't refer to the final decoder in the network. An output layer is a specific type of layers that implements a loss function for the purpose of training,
You must have one of these as the final layer in your network, so that trainNetwork knows what loss function to use.

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by