# Why would a symmetric image have an asymmetric PoolingLayer-Gradient Image?

I have a symmetric image img. For simplicity, I would use the below image as my example:

img = Rasterize@Graphics[{Red, Rectangle[]}]


As you can see, img is an image of a pure red square with four thin white margins. Now I put it into a neural network with a pooling layer only (and the PartLayer which is used to extract the red color), and then extract the gradient.

pool = NetChain[{PoolingLayer[10, "Input" -> "Image"], PartLayer[1]}]


As you can see, the gradient image has a "black-L" at the margin.

The input image is symmetric, while the pooling layer (and the PartLayer) have no parameters to be trained. That means everything should be symmetric, but the gradient is asymmetric. Why?

Many thanks!

It is black because it zeros out the values in the dimensions it collapses, for example:

In[1]:= pool = PoolingLayer[{2}]
In[6]:= pool@{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}
Out[6]= {{1., 1.}, {1., 1.}, {1., 1.}}

In[7]:= pool[{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}},
Out[7]= {{1., 1., 0.}, {1., 1., 0.}, {1., 1., 0.}}


So the black strips correspond to the 9 dropped columns and rows from the 10x10 pooling.

However, it looks like there may be a bug in the documentation, which shows this example:

But the result is not what we expect when executed (v11.3):

Without the ImageAdjust it looks like this:

• Can anyone confirm that is a bug? – M.R. Feb 6 '19 at 20:23