Fatemeh
Fatemeh

Reputation: 1

Incompatibility of output size of pooling layer in CNN model described in Caffe vs Matlab

I have a Caffe CNN model, and I am trying to import it to MATLAB using importCaffeNetwork command, which gets prototxt and caffemodel files as input arguments.
However, I get this error:

The pooling layer 'pool1' is not compatible with MATLAB. 
Caffe computes the output size as [16 16 32] but MATLAB computes it as [15 15 32]

It seems that the error is related to the difference in output size calculation of pooling layer in MATLAB and CAFFE, where the former uses ceil and the latter uses floor function.

Is it the real source of problem? What can I do to solve this?

Upvotes: 0

Views: 1458

Answers (1)

jdhao
jdhao

Reputation: 28449

This is because in caffe, the output size calculation for convolution layers and pooling layers are slightly different. Suppose input dim is h, padding is p, kernel size is k and stride is s, for convolutional layers, the output size is floor((h+2*p-k)/s)+1, but for pooling layers, the output size is ceil((h+2*p-k)/s)+1.

So the output size is different even if the parameters and input size are the same.

How to solve this problem?

Adjust the parameter such as padding and stride and kernel size to ensure that the output is the same.

References

  1. Pooling layer output size calculation source code, https://github.com/BVLC/caffe/blob/master/src/caffe/layers/pooling_layer.cpp#L90
  2. Conv layers output size calculation source code, https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cpp#L18

Upvotes: 4

Related Questions