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

14 visualizaciones (últimos 30 días)
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

Respuestas (1)

Sanjana
Sanjana el 9 de Jun. de 2023
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!

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by