'How to mimic tensorflow maxpool in Caffe1

I working on a Caffe application on a Jetson TX2, currently I have a single maxpool layer constructed as follows

caffe::LayerParameter layer_parameter;
caffe::PoolingParameter *pooling_parameter = layer_parameter.mutable_pooling_param();
pooling_parameter->set_kernel_h(2);
pooling_parameter->set_kernel_w(2);
pooling_parameter->set_stride(2);

std::shared_ptr<caffe::Layer<float>> pooling_layer(new caffe::PoolingLayer<float>(layer_parameter));

std::vector<caffe::Blob<float>*> bottom_vector;
std::vector<caffe::Blob<float>*> top_vector;
bottom_vector.push_back(input_tensor);
top_vector.push_back(output_tensor);

pooling_layer->SetUp(bottom_vector, top_vector);

pooling_layer->Forward(bottom_vector, top_vector);

The idea of the layer is to mimick the behavior of tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2, padding='same') unfortunately with the same input, a tensor with shape (1,4,4,2) filled with numbers from 0 to 31, I get two different outputs.

On Caffe the output is the following [[[[3, 7][11, 15]] [[19, 23][27, 31]]]] while on Tensorflow the output is [[[[10, 11] [14, 15]] [[26, 27][30, 31]]]].

Is there a way to modify Caffe's options to obtain the same output on both programs?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source