onnx2torch icon indicating copy to clipboard operation
onnx2torch copied to clipboard

AvgPool with non symmetrical padding is not implemented

Open jamesWalker55 opened this issue 1 year ago • 1 comments

I'm trying to convert a model from onnx to pytorch, however I'm get the following error:

     43 padding, padding_module = onnx_auto_pad_to_torch_padding(
     44     onnx_padding=node_attributes.get('pads', [0] * spatial_rank * 2),
     45     auto_pad=node_attributes.get('auto_pad', 'NOTSET'),
     46 )
     47 if padding_module is not None:
---> 48     raise NotImplementedError('AvgPool with non symmetrical padding is not implemented.')
     50 torch_module = avgpool_class(
     51     kernel_size=kernel_shape,
     52     stride=strides,
   (...)
     55     ceil_mode=ceil_mode == 1,
     56 )
     58 return OperationConverterResult(
     59     torch_module=torch_module,
     60     onnx_mapping=onnx_mapping_from_node(node=node),
     61 )

NotImplementedError: AvgPool with non symmetrical padding is not implemented.

jamesWalker55 avatar Aug 18 '23 11:08 jamesWalker55

I’m not sure whether this change is correct but it appears to work:

     padding, padding_module = onnx_auto_pad_to_torch_padding(
         onnx_padding=node_attributes.get('pads', [0] * spatial_rank * 2),
         auto_pad=node_attributes.get('auto_pad', 'NOTSET'),
     )   
-    if padding_module is not None:
-        raise NotImplementedError('AvgPool with non symmetrical padding is not implemented.')
 
     torch_module = avgpool_class(
         kernel_size=kernel_shape,
         stride=strides,
         padding=padding,
         count_include_pad=count_include_pad == 1,
         ceil_mode=ceil_mode == 1,
     )   
 +   
 +   if padding_module is not None:
 +       torch_module = nn.Sequential(padding_module, torch_module)
 
     return OperationConverterResult(
         torch_module=torch_module,
         onnx_mapping=onnx_mapping_from_node(node=node),
     )

palant avatar Jan 20 '24 11:01 palant