Reputation: 411
Is there an existing implementation of sum pooling in tensorflow? When searching the documentation, it seems that only average and max pooling operations are supported.
I have a NHWC tensor where each HxW matrix is a probability map which I would like to downsample via 2x2 sum pooling. If a sum pooling function does not exist in tensorflow, is there another way I could implement this downsampling operation using the Python API?
Upvotes: 1
Views: 3099
Reputation: 24661
There is no such thing in tensorflow at the moment. The next best thing is probably to just multiply the output of an average pooling by 4. Element-wise multiplication is fast enough not to worry about this added step.
You do loose a pair of bits of precision in the process though.
An alternative would be to compute the sum yourself, e.g.
y = (x[:, 0::2, 0::2] +
x[:, 1::2, 0::2] +
x[:, 0::2, 1::2] +
x[:, 1::2, 1::2])
It should be slower than the previous solution, but the precision may be slightly better, if that is important to you.
Upvotes: 5
Reputation: 222969
User already told you that you can leverage avg pooling to get sum pooling. He also mentioned that you might loose precision (but this is highly unlikely and in most of the cases irrelevant).
Here is another easy approach. You can use 2d convolution with strides to calculate sum pooling. Your kernel would be a matrix of ones.
Upvotes: 0