Squeeze-an​d-Excitati​on-Incepti​on Architecture for 1D-CNN in MATLAB: Input Data Format Specification and Dimension Matching Issues Between Modules

I have one-dimensional spectral series data in the original format of 2623×377, where 2623 is the number of data points per sample (sequence length), and 377 is the number of samples. I have built a 1D-CNN architecture based on Inception and added a Squeeze-and-Excitation (SE) attention module.
First issue: I am unsure about the specific data dimension order expected by 1D-CNN in MATLAB. I have converted the 2623×377 data into a 2623×1×377 (SCB) format that the network can accept. I am not sure if this is correct.
Second issue: How can I properly match the output of the SE module to the same dimensions as the Inception module for multiplication?
The SE module (the penultimate tempLayers) requires global pooling → fully connected layer → weight calculation → multiplication with the original feature map. However, I encountered a dimension mismatch issue. The SE module outputs [64(C)×1(B)], while the Inception output is [1312(S)×64(C)×1(B)]. The MATLAB multiplication layer requires all inputs to have the same dlarray format. I tried using a functionLayer for reshape operations but failed to achieve the correct dimension transformation. I encountered a format mismatch error: "All inputs of layer 'nnet.cnn.layer.MultiplicationLayer' must be formatted dlarray objects with the same format."
After some attempts, I found that the Inception output [1312(S)×64(C)×1(B)] and the global average pooling output [1(S)×64(C)×1(B)] can be multiplied using the multiplicationLayer. However, after passing through the fully connected layer, the global average pooling output [1(S)×64(C)×1(B)] becomes 64(C)×1(B). How can I reshape the sigmoid layer output back to 1(S)×64(C)×1(B)? Thank you very much for your help.
clc;
Xcal=rand(2623,377);
Xtest=rand(2623,94);
ycal=rand(377,1);
ytest=rand(94,1);
Xcal = dlarray(reshape(Xcal, [2623, 1, 377]), 'SCB');
ycal = dlarray(ycal, 'BC');
Xtest = dlarray(reshape(Xtest, [2623, 1, 94]), 'SCB');
ytest = dlarray(ytest, 'BC');
%%creat network
lgraph = layerGraph();
tempLayers = [
inputLayer([2623,1,NaN], "SCB")
convolution1dLayer(11,32,'Name','conv1_initial','Padding','same')
batchNormalizationLayer('Name','bn1_initial')
reluLayer('Name','relu1_initial')
maxPooling1dLayer(2,'Stride',2,'Name','pool1_initial','Padding','same')];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
convolution1dLayer(1,16,'Name','conv_inception_1x1','Padding','same')
batchNormalizationLayer('Name','bn_inception_1x1')
reluLayer('Name','relu_inception_1x1')];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling1dLayer(3,'Name','pool_inception','Padding','same')
convolution1dLayer(1,16,'Name','conv_inception_pool','Padding','same')
batchNormalizationLayer('Name','bn_inception_pool')
reluLayer('Name','relu_inception_pool')];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
convolution1dLayer(1,16,'Name','conv_inception_1x1_1','Padding','same')
batchNormalizationLayer('Name','bn_inception_1x1_1')
reluLayer('Name','relu_inception_1x1_1')
convolution1dLayer(3,16,'Name','conv_inception_3x3','Padding','same')
batchNormalizationLayer('Name','bn_inception_3x3')
reluLayer('Name','relu_inception_3x3')];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
convolution1dLayer(1,16,'Name','conv_inception_1x1_2','Padding','same')
batchNormalizationLayer('Name','bn_inception_1x1_2')
reluLayer('Name','relu_inception_1x1_2')
convolution1dLayer(5,16,'Name','conv_inception_5x5','Padding','same')
batchNormalizationLayer('Name','bn_inception_5x5')
reluLayer('Name','relu_inception_5x5')];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = depthConcatenationLayer(4,'Name','inception_concat');
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
globalAveragePooling1dLayer('Name','se_global_pool')
fullyConnectedLayer(8,'Name','se_fc_reduce')
reluLayer('Name','se_relu_reduce')
fullyConnectedLayer(64,'Name','se_fc_expand')
sigmoidLayer('Name','se_sigmoid')
functionLayer(@(X) reshape(X, [1, size(X,1), size(X,2)]), 'Name', 'se_reshape')];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
multiplicationLayer(2,'Name','se_scale')
convolution1dLayer(7,64,'Name','conv2_secondary','Padding','same')
batchNormalizationLayer('Name','bn2_secondary')
reluLayer('Name','relu2_secondary')
maxPooling1dLayer(2,'Stride',2,'Name','pool2_secondary','Padding','same')
fullyConnectedLayer(128,'Name','fc1_final')
reluLayer('Name','relu_fc1')
dropoutLayer(0.5,'Name','dropout_final')
fullyConnectedLayer(64,'Name','fc2_final')
reluLayer('Name','relu_fc2')
fullyConnectedLayer(1,'Name','fc_output')];
lgraph = addLayers(lgraph,tempLayers);
clear tempLayers;
lgraph = connectLayers(lgraph,'pool1_initial','conv_inception_1x1');
lgraph = connectLayers(lgraph,'pool1_initial','pool_inception');
lgraph = connectLayers(lgraph,'pool1_initial','conv_inception_1x1_1');
lgraph = connectLayers(lgraph,'pool1_initial','conv_inception_1x1_2');
lgraph = connectLayers(lgraph,'relu_inception_1x1','inception_concat/in1');
lgraph = connectLayers(lgraph,'relu_inception_pool','inception_concat/in4');
lgraph = connectLayers(lgraph,'relu_inception_3x3','inception_concat/in2');
lgraph = connectLayers(lgraph,'relu_inception_5x5','inception_concat/in3');
lgraph = connectLayers(lgraph,'inception_concat','se_global_pool');
lgraph = connectLayers(lgraph,'inception_concat','se_scale/in1');
lgraph = connectLayers(lgraph,'se_reshape','se_scale/in2');
options = trainingOptions('adam', ...
'MaxEpochs', 300, ...
'InitialLearnRate', 1e-3, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.5, ...
'LearnRateDropPeriod', 50, ...
'L2Regularization', 1e-5, ...
'ValidationData', {Xtest,ytest}, ...
'ValidationFrequency', 15, ...
'MiniBatchSize', 16, ...
'Verbose', true, ...
'Plots', 'training-progress', ...
'Shuffle', 'every-epoch', ...
'ExecutionEnvironment', 'cpu');
dlnet = dlnetwork(lgraph);
net = trainnet(Xcal,ycal, dlnet, 'mse', options);
Yp=predict(net,Xtest);
Yt=predict(net,Xcal);
Yp=extractdata(Yp);
Yt=extractdata(Yt);
ytest=extractdata(ytest);
ycal=extractdata(ycal);
R2p = 1-sum((Yp-ytest).^2)/sum((ytest- mean(ytest)).^2);
R2t =1-sum((Yt -ycal).^2)/sum((ycal- mean(ycal)).^2);

 Accepted Answer

@dachen wang. For the first issue, the documentation of convolution1dLayer states that the desired input format of convolution1dLayer is "SCB"/"CBT"/"SCBT" corresponding to 1-D image input/time-series input/1-D image sequence input/ respectively. For the second issue, I think the best practice to construct complex neural network is buliding massive layers incrementlly. In the incremental construction procedure, you can examine the neural network model and debug it step by step. By the way, the layerGraph is not recommended, use dlnetwork instead.

5 Comments

Thank you for your patient answer. Now I can determine that the problem lies in the step of multiplying the output of SE module by that of Inception module. The SE module outputs [64(C)×1(B)], while the Inception output is [1312(S)×64(C)×1(B)]. I found that the Inception output [1312(S)×64(C)×1(B)] and the global average pooling output [1(S)×64(C)×1(B)] can be multiplied using the multiplicationLayer. However, after passing through the fully connected layer, the global average pooling output [1(S)×64(C)×1(B)] becomes 64(C)×1(B). Running the following code does not achieve the function I expected. How can I reshape the final output of SE module back to 1(S)×64(C)×1(B)? Thank you very much for your help.
functionLayer(@(X) reshape(X, [1, size(X,1), size(X,2)]), 'Name', 'se_reshape');
@dachen wang. After querying the MATLAB documentation, I find there is a reshapeLayer introduced in the R2025a, which can be used for reshaping input. This layer may be useful to reshape the output of SE module back to 1(S)✖64(C)✖1(B).
Thank you very much. The reshapelayer you recommended can solve my problem. Because this layer was missing in the Deep Network Designer of version R2025b, I couldn't find it when I was building the network. But I can achieve it by inputting code in the script.
By the way, I also want to ask why this layer is missing in the R2025b version. How can I find some layers that are not present in the new version but exist in the old one in the future?
@dachen wang. I hardly use Deep Network Designer or other App. I like to complete projects by writing MATLAB code, since I think it is better to understand the logic of code execution and debug. The missing of reshapeLayer in R2025b may be some bugs, you can report this issue to MathWorks through bugreports.

Sign in to comment.

More Answers (0)

Products

Release

R2025b

Community Treasure Hunt

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

Start Hunting!