0

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?

Shai
  • 111,146
  • 38
  • 238
  • 371
Fatemeh
  • 1
  • 4

1 Answers1

4

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
Community
  • 1
  • 1
jdhao
  • 24,001
  • 18
  • 134
  • 273
  • Thanks for the information about the source of problem. However, adjusting the variables in this way is limiting. Is there any way to change some sort of settings? Or is it possible to simply modify the mentioned codes such that this problem does not arise at all? – Fatemeh Oct 07 '17 at 08:04
  • Maybe you can paste the part of code that is relevant to this problem so that I can know what the problem is. – jdhao Oct 07 '17 at 08:15
  • I mean that, is it possible that I change just this part of code in CAFFE and "make" it again to become compatible with MATLAB? – Fatemeh Oct 11 '17 at 11:29