When I try to modify the matlab provided cnn network, it says layer 11 is expected to have a different size.

1 次查看(过去 30 天)
Here are the layer parameter.
varSize = 32;
conv1 = convolution2dLayer(5,varSize,'Padding',2,'BiasLearnRateFactor',2);
conv1.Weights = gpuArray(single(randn([5 5 3 varSize])*0.0001));
fc1 = fullyConnectedLayer(64,'BiasLearnRateFactor',2);
fc1.Weights = gpuArray(single(randn([64 576])*0.1));
fc2 = fullyConnectedLayer(4,'BiasLearnRateFactor',2);
fc2.Weights = gpuArray(single(randn([4 64])*0.1));
layers = [
imageInputLayer([varSize varSize 3]);
conv1;
maxPooling2dLayer(3,'Stride',2);
reluLayer();
convolution2dLayer(5,32,'Padding',2,'BiasLearnRateFactor',2);
reluLayer();
averagePooling2dLayer(3,'Stride',2);
convolution2dLayer(5,64,'Padding',2,'BiasLearnRateFactor',2);
reluLayer();
averagePooling2dLayer(3,'Stride',2);
fc1;
reluLayer();
fc2;
softmaxLayer()
classificationLayer()];

回答(1 个)

Elizabeth Reese
Elizabeth Reese 2017-12-5
When you specify the weights for fc1 and fc2, the 576 and 64 respectively is taken as the expected output size from the previous layer. You can double check that this is correct using the formulas at the bottom of the layers' documentation pages to follow through what the output size is expected to be at that point. You can test this hypothesis by removing your assignments to the weights and seeing if the network will train and what the sizes are at that stage.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by