Input size mismatch. Size of input to this layer is different from the expected input size.
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
Sanjana
il 9 Giu 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!
0 Commenti
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!