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

Debraj Maji
Debraj Maji 2023년 12월 28일
Can you please share the code for the network?
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 2023년 12월 28일
이동: Matt J 2023년 12월 28일
What do you want the output of your network to be? The output options can be viewed here:

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

답변 (1개)

Matt J
Matt J 2023년 12월 28일
편집: Matt J 2023년 12월 29일

0 개 추천

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.

카테고리

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

제품

릴리스

R2023b

질문:

2023년 12월 27일

편집:

2023년 12월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by