In a custom CNN network, how can I know about the input size for each layer?
Show older comments
For preparing the type of table as shown in the above figure,how can I get values for the last column of the table i.e Input Size for each layer in my CNN model?
Answers (1)
Image Analyst
on 23 Jun 2022
When you build a custom network, for example like this:
layers = [
imageInputLayer([227, 227, 3])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
averagePooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
averagePooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
dropoutLayer(0.2)
fullyConnectedLayer(1)
regressionLayer];
the 227 is not something you "get". It's something you specify. Bigger images take longer to train but will be more accurate. If your accuracy is low, try increasing the size of images you supply.
If you're doing transfer learning, like adapting alexnet or googlenet, then you need to know what image sizes they want and make sure you supply images of that size.
4 Comments
debojit sharma
on 23 Jun 2022
Ben
on 24 Jun 2022
You can get this information from analyzeNetwork. For example I can take @Image Analyst's network and do:
analyzeNetwork(layers)
The input size of a layer is equivalent to the activation size of the layers that connect into it. So for example the input size of conv_3 below is 56 x 56 x 16 as that's the activation size of the preceding layer:

debojit sharma
on 1 Jul 2022
debojit sharma
on 2 Jul 2022
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!