Cant get concatenationLayer to connect to other layers in my CNN

6 次查看(过去 30 天)
When I used connectLayers and plot(lgraph) everything is connected properly, but when I use analyzeNetwork, none of my connections seem to have made it through.
The error states "Unconnected input. Each layer input must be connected to the output of another layer. Detected unconnected inputs: input 'in2'.
Codes = imageDatastore('Desktop/Data_Old/Train_Data/Codes','IncludeSubfolders',true);
Eyes = imageDatastore('/Desktop/Data_Old/Train_Data/Eyes','IncludeSubfolders',true);
imds = combine(Eyes,Codes);
miniBatchSize = 64;
Layers = [
%trunk
imageInputLayer([280 320 1],'Normalization','none','Name','Input');
convolution2dLayer(5,64,'Name','conv1_1')%input size: 280x320 output size: 276x316
batchNormalizationLayer('Name','BN1')
reluLayer('Name','conv1')
maxPooling2dLayer(5,'Name','pool1')
%main branch
concatenationLayer(2,2,'Name','cat1')%not sure if 2 is correct expecting 272x624
convolution2dLayer(5,64,'Stride',[2 2],'Name','conv21_1');
batchNormalizationLayer('Name','BN2')
reluLayer('Name','conv21','Name','RL1')
convolution2dLayer(4,64,'Padding',[2 2],'Name','CONV22_1');
batchNormalizationLayer('Name','BN3')
reluLayer('Name','conv22')
convolution2dLayer(4,64,'Padding',[2 2],'Name','CONV23_1');
batchNormalizationLayer('Name','BN4')
reluLayer('Name','conv23')
convolution2dLayer(5,64,'Stride',[2 2],'Name','CONV24_1');
batchNormalizationLayer('Name','BN5')
reluLayer('Name','conv24')
convolution2dLayer(2,64,'Stride',[2 1],'Name','CONV25_1');
batchNormalizationLayer('Name','BN6')
reluLayer('Name','conv25')
transposedConv2dLayer(2,64,'Stride',[1 2],'Name','CONV26_1');
batchNormalizationLayer('Name','BN7')
reluLayer('Name','conv26')
transposedConv2dLayer(2,64,'Stride',[1 2],'Name','CONV27_1');
batchNormalizationLayer('Name','BN8')
reluLayer('Name','conv27')
transposedConv2dLayer([2 50],64,'Name','CONV28_1');
batchNormalizationLayer('Name','BN9')
reluLayer('Name','conv28')
transposedConv2dLayer([2 50],64,'Name','CONMV29_1');
batchNormalizationLayer('Name','BN10')
reluLayer('Name','conv29')
%Branch1
convolution2dLayer(5,64,'Name','convB11');
reluLayer('Name','rl2');
batchNormalizationLayer('Name','BN11')
maxPooling2dLayer(2,'Padding',[1 1],'Stride',[2 2],'Name','poolB1')
concatenationLayer(2,2,'Name','cat2')%not sure if 2 is correct expecting 134x308
convolution2dLayer([3 3],64,'Padding',[2 3],'Stride',[1 2],'Name','CONVB12_1');
batchNormalizationLayer('Name','BN12')
reluLayer('Name','convB12')
transposedConv2dLayer(2,64,'Stride',[2 2],'Name','DECONVB11_1')
batchNormalizationLayer('Name','BN13')
reluLayer('Name','deconvB11')
%Branch2
convolution2dLayer(5, 64,'Name','convB21');
batchNormalizationLayer('Name','BN14')
reluLayer('Name','RL3');
maxPooling2dLayer(4,'Padding',[1 1],'Stride',[2 2],'Name','poolB2')
concatenationLayer(2,2,'Name','cat3') %not sure if 2 is correct expecting 64x148
convolution2dLayer([4 3],64,'Padding',[3 4],'Stride',[1 2],'Name','CONVB22_1');
batchNormalizationLayer('Name','BN15')
reluLayer('Name','convB22')
transposedConv2dLayer(2,64,'Stride',[2 2],'Name','DECONVB21_1');
batchNormalizationLayer('Name','BN16')
reluLayer('Name','deconvB21');
%Branch3
convolution2dLayer(5,64,'Name','convB31');
batchNormalizationLayer('Name','BN17')
reluLayer('Name','RL4');
maxPooling2dLayer(4,'Padding',[1 1],'Stride',[2 2],'Name','poolB3')
convolution2dLayer([5 4],64,'Padding',[4 3],'Name','CONVB32_1');
batchNormalizationLayer('Name','BN18')
reluLayer('Name','convB32')
transposedConv2dLayer(2,64,'Stride',[2 2],'Name','DECONVB31_1')
batchNormalizationLayer('Name','BN19')
reluLayer('Name','deconvB31')
%Output
transposedConv2dLayer([2 19],64,'Name','DECONV_1');
batchNormalizationLayer('Name','BN20')
reluLayer('Name','deconv1')
regressionLayer('Name','Output')
];
lgraph = layerGraph(Layers);
lgraph = disconnectLayers(lgraph,'conv29','convB11');
lgraph = disconnectLayers(lgraph,'deconvB31','DECONV_1');
lgraph = disconnectLayers(lgraph,'deconv1','convB11');
lgraph = disconnectLayers(lgraph,'deconvB11','convB21');
lgraph = disconnectLayers(lgraph,'deconvB21','convB31');
lgraph = connectLayers(lgraph,'pool1','convB11');
lgraph = connectLayers(lgraph,'poolB1', 'convB21');
lgraph = connectLayers(lgraph,'poolB2', 'convB31');
lgraph = connectLayers(lgraph,'conv29','DECONV_1');
lgraph = connectLayers(lgraph,'deconvB11','cat1/in2');
lgraph = connectLayers(lgraph,'deconvB21','cat2/in2');
lgraph = connectLayers(lgraph,'deconvB31','cat3/in2');
plot(lgraph)
analyzeNetwork(Layers)
% options = trainingOptions('adam', ...
% 'InitialLearnRate',3e-4, ...
% 'MaxEpochs',5, ...
% 'Shuffle','every-epoch', ...
% 'Verbose',false, ...
% 'ExecutionEnvironment','parallel',...
% 'Plots','training-progress');
%
% net_RBDN = trainNetwork(imds , Layers, options);
% save(net_RBDN);
output from plot(lgraph)
output from analyzeNetwork

采纳的回答

Frank Mosely
Frank Mosely 2020-11-28
Turns out that when you modify your network the arguments to trainNetwork and analyzeNetwork change. whomp.
So above, I should have said analyzeNetwork(lgraph)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by