onnx2keras icon indicating copy to clipboard operation
onnx2keras copied to clipboard

Padding layer default mode missing

Open bwery opened this issue 3 years ago • 2 comments

It appears that the "mode" parameter in ONNX padding layers is optional, and a default 'constant' value is to be considered in this case (see in [https://github.com/onnx/onnx/blob/master/docs/Operators.md#Pad]).

I have a ONNX model to convert where this mode parameter is missing on some pad layer and this caused the conversion to fail.

I have implemented a workaround replacing line 19 in file padding_layers.py

params['mode'] = params['mode'].decode('ascii')

with following code:

    try:
        params['mode'] = params['mode'].decode('ascii')
    except:
        params['mode'] = 'constant'

This solves the issue.

bwery avatar Mar 09 '21 17:03 bwery

Hi, @bwery ! As I can understand from Onnx documentation: constant is the default mode.

mode : string (default is constant)
Supported modes: `constant`(default), `reflect`, `edge`

It's quite strange that some layers don't have a pad 'mode' attribute.

If you want, you can make PR for your changes or we will fix it a little bit later. Thank you for your interest in the project!

Andredance avatar Apr 07 '21 10:04 Andredance

Hello, I am not used with the introduction of pull requests on Github. So, i would prefer somebody skilled makes the change !

Thank you anyway for your answer !

bwery avatar Apr 07 '21 11:04 bwery