Input size mismatch. Size of input to this layer is different from the expected input size.

9 次查看(过去 30 天)
Hello all,
I wanted to modify Alexnet with 512x512x3 input pictures, even though it shows an error and I would ne more than thankful if one tells me how to get over it. My layers is as follow:
LayersTransfer=net.Layers(2:end-3);
Layers=[imageInputLayer([ N, M, 3])
convolution2dLayer(11,96,'Stride',2,'Padding',0,'NumChannels',3)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(3,'Stride',2,'Padding',0)
LayersTransfer
fullyConnectedLayer(Num_out_class,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer
classificationLayer];
The issue comes out when I want to connect maxPooling2dLayer(3,'Stride',2,'Padding',0) to the next Conv2D layer, although the size of output from maxpooling is 125x125x96. The size of next Conv2d layer after maxpooling is convolution2dLayer(11,96,'Stride',4,'Padding',0,'NumChannels',3) and the respective weights and bias 11x11x3x96 bias 1x1x96.
Please help me

回答(1 个)

Sanjana
Sanjana 2023-6-9
Hi Hamed,
I understand, you want to modify the AlexNet network to train with images of size 512x512x3 and modifying the input size of the “imageInputLayer”, can is causing mismatch in the inputSize at the fully connected layers.
The reason for the above issue, is because fully connected layers expect fixed size input, and as you have been passing input with different dimensions, you also need to configure the fully connected layer, so that it matches the new input dimensions.
“fullyConnectedLayer” automatically detects the size of input being passed to it. So, you can try to replace the “fullyConnectedLayer” with a new layer like this,
new_layer = fullyConnectedLayer(4096);
layer_graph_new = replaceLayer(layer_graph,'fc6',new_layer);
Hope this helps!

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by