Skip to content

Wrong rounding-type for Pooling layers after converting a MXNet model to IR #24

@rocketbear

Description

@rocketbear

In the original MXNet model, the pooling layer is defined with ceil_mode=False (resulting in pooling_convention=valid in the json file). But in the xml file of the converted IR, the rounding-type is "ceil". This causes the network producing incorrect results after CNNNetwork::reshape is called (which probably re-calculates the shape of the blobs) even if the input width and height are not changed.

op definition in MXNet json file:

{
  "op": "Pooling", 
  "name": "pool_fwd", 
  "attrs": {
    "global_pool": "False", 
    "kernel": "(3, 3)", 
    "pad": "(1, 1)", 
    "pool_type": "max", 
    "pooling_convention": "valid", 
    "stride": "(2, 2)"
  }, 
  "inputs": [[4, 0, 0]]
}

Layer in xml file of the IR:

	<layer id="3" name="pool_fwd" precision="FP32" type="Pooling">
		<data exclude-pad="false" kernel-x="3" kernel-y="3" pad-b="1" pad-r="1" pad-x="1" pad-y="1" pool-method="max" rounding-type="ceil" stride="1,1,2,2" stride-x="2" stride-y="2"/>
		<input>
			<port id="0">
				<dim>1</dim>
				<dim>32</dim>
				<dim>112</dim>
				<dim>112</dim>
			</port>
		</input>
		<output>
			<port id="1">
				<dim>1</dim>
				<dim>32</dim>
				<dim>56</dim>
				<dim>56</dim>
			</port>
		</output>
	</layer>

This problem seems to be caused by the following code in mo.front.mxnet.extractors.pooling.py:

pooling_conv = attrs.str("pooling_convention", 'valid')
if pooling_conv:
    data["pooling_convention"] = pooling_conv
    data["rounding_type"] = 'ceil'

I have modified the code as follows and then the network is correct:

pooling_conv = attrs.str("pooling_convention", 'valid')
if pooling_conv:
    data["pooling_convention"] = pooling_conv
    if pooling_conv == 'valid':
        data["rounding_type"] = 'floor'
    else:
        data["rounding_type"] = 'ceil'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions