Problem with CNN architecture for small images of size 6x6

1 回表示 (過去 30 日間)
Muhammad Jaleed Khan
Muhammad Jaleed Khan 2017 年 5 月 22 日
コメント済み: Javier Pinzón 2017 年 10 月 25 日
I'm trying to develop a CNN classifier for a large dataset of small images of size 6x6. I have modified the original code of an example (Train a Convolutional Neural Network Using Data in ImageDatastore) from MATLAB Help. I need to increase number of layers to the network more deep to get better results.
Original Code of CNN layers:
layers = [imageInputLayer([28 28 1]);
convolution2dLayer(5,20);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
fullyConnectedLayer(5);
softmaxLayer();
classificationLayer()];
Modified Code of CNN layers:
% Define the convolutional neural network architecture.
layers = [imageInputLayer([6 6 1]);
convolution2dLayer(5,20,'Padding',3);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
convolution2dLayer(5,20);
reluLayer();
maxPooling2dLayer(5,'Stride',2);
fullyConnectedLayer(5);
softmaxLayer();
classificationLayer()];
Now I am getting this error:
Error using nnet.cnn.layer.Layer>iInferSize (line 261)
Layer 7 is expected to have a different size.
It is expecting the pooling layer to have different size. I have tried 2x2 and 3x3 sizes of pooling layer but it gives the same errors. Please help me fix this issue so that I can add more number of layers to the CNN.

回答 (1 件)

Javier Pinzón
Javier Pinzón 2017 年 6 月 1 日
編集済み: Javier Pinzón 2017 年 6 月 1 日
Hello Muhammad,
First of all, you have errors when calculating the output volumen of each layer. Lets check:
Convolution 1:
OutV1 = (6 - 5 + 3*2)/1 + 1 = 8
Maxpooling:
OutV2 = 8 / 2 = 4
Convolution 2:
OutV3 = (4 - 5)/1 + 1 = 0
And then... you dont have any output volume from convolution 2 ownwards... so you need to recalculate your filter sizes... I really recommend you to use sizes of 2 or 3 in the convolutions, and also add some padding of the size of the filter - 1 in each convolution layer, to keep a considerably volumen, i.e., if you use a filter of size of 3, use "padding" = 1, so you will have:
Out volume = (In - 3 + 2*1)/1 + 1 = In
Remember:
Output Volume = [("Input Volumen" - "Filter Size" + 2 * "Padding")/"Stride"] + 1
hope it helps if it is not too late =)
  2 件のコメント
shubham gupta
shubham gupta 2017 年 10 月 21 日
why +1 is added to Output Volume
Javier Pinzón
Javier Pinzón 2017 年 10 月 25 日
+1 is related to the "Bias", each layer has the activation neuron, for that reason there is a +1 in the formula

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by