Error Network: Missing output layer

18 次查看(过去 30 天)
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 个评论
Fernando Bonilla Hidrobo
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);

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2023-12-28
编辑:Matt J 2023-12-29
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.

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by