This issue arises due to size mismatch between the ground truth and the network output and may be resolved by setting the “Padding’’ attribute of the “maxPooling2dLayer” appropriately.
In the above code, the stride value is set to 1 which is less than the pool layer size (2x2). This causes overlapping regions of the input to be processed by the pool layer. The output image size in this case is given by the following formula
(Input Size – Pool Size + 2*Padding)/Stride + 1.
For instance, consider the first pooling layer. Here
- Input Size: 256*256*3
- Pool Size: 2*2
- Padding: 0
- Stride: 1
Here the output size will be 255*255*3.
Each subsequent pooling layer will reduce the height and width of the input by 1. After 3 maxpooling layers output will be of size (253*253*3).
By setting the ‘Padding’ attribute to [1 1], the size of the image remains same. Please make use of the following syntax to change the ‘Padding’
maxPooling2dLayer(2,'Name','maxPooling1', 'stride', 1, ’Padding’ ,[1 1])
Please refer to the following documentation link on maxpooling layer