mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Pooling operator expects kernel size even when 'global_pool' is set to True

Open indhub opened this issue 9 years ago • 4 comments

Pooling operator expects kernel size even when 'global_pool' is set to True. If 'global_pool' is true, kernel should automatically be set to (height, width). User shouldn't have to provide kernel size.

Environment info

Operating System: Ubuntu

Compiler: gcc

Package used (Python/R/Scala/Julia): Python

MXNet version: 0.10

Or if installed from source:

MXNet commit hash (git rev-parse HEAD):

If you are using python package, please provide

Python version and distribution: Python 2.7.12

If you are using R package, please provide

R sessionInfo():

Error Message:

Traceback (most recent call last):
  File "resnet50.py", line 965, in <module>
    name='pool5')
  File "/usr/local/lib/python2.7/dist-packages/mxnet-0.10.0-py2.7.egg/mxnet/_ctypes/symbol.py", line 181, in creator
    ctypes.byref(sym_handle)))
  File "/usr/local/lib/python2.7/dist-packages/mxnet-0.10.0-py2.7.egg/mxnet/base.py", line 84, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Required parameter kernel of Shape(tuple) is not presented, in operator Pooling(name="", global_pool="True", pool_type="avg")

Minimum reproducible example

pool5 = mx.symbol.Pooling(data=data,
    pool_type='avg',
    global_pool=True,
    #kernel=(1,1),
    name='pool')

Steps to reproduce

or if you are running standard examples, please provide the commands you have run that lead to the error.

  1. Create a pooling layer with 'global_pool' set to True and kernel size not set (like shown above)
  2. Run the code.

indhub avatar Sep 08 '17 18:09 indhub

'kernel=(1,1)' is a good setting and It's convenient for FCN. Please refer to https://stackoverflow.com/questions/42070528/what-does-global-pooling-do

chinakook avatar Sep 09 '17 14:09 chinakook

The kernel parameter is required to determine whether the Pooling Operation is 1d or 2d or 3d based on the shape of the kernel. This is also used to determine the shape of stride. The size of each dimension in kernel doesn't matter when the global_pool is set to True. https://github.com/apache/incubator-mxnet/blob/master/src/operator/pooling-inl.h#L104 https://github.com/apache/incubator-mxnet/blob/master/src/operator/pooling-inl.h#L107

anirudh2290 avatar Sep 27 '17 00:09 anirudh2290

Since the documentation was not clear to indhub@, is there an opportunity here to clarify/improve the API documentation? What is we update the document to say: from: global_pool (boolean, optional, default=False) – Ignore kernel size, do global pooling based on current input feature map. to: (something like this) global_pool (boolean, optional, default=False) – Ignore kernel size, but the kernel must be specified to determine the shape of the stride and whether the Pooling Operation is 1d or 2d or 3d based on the shape of the kernel. Do global pooling based on current input feature map.

bhavinthaker avatar Oct 02 '17 20:10 bhavinthaker

@indhub this does not seem necessary anymore. Please close:


pool5 = mx.symbol.Pooling(data=mx.sym.var('data'),
    pool_type='avg',
    global_pool=True,
    name='pool')
​
mx.test_utils.simple_forward(pool5, data=np.ones((1,3,224,224)))
array([[[[ 1.]],

        [[ 1.]],

        [[ 1.]]]], dtype=float32)

ThomasDelteil avatar Jul 30 '18 21:07 ThomasDelteil