Skip to content

Commit

Permalink
Support dynamic pads for Pad opset 11 (#45)
Browse files Browse the repository at this point in the history
* Support dynamic pads for Pad opset 11
  • Loading branch information
jiafatom authored Jan 15, 2020
1 parent 9bc1744 commit c452903
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions onnxconverter_common/onnx_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ def apply_pad(scope, input_name, output_name, container, operator_name=None, mod
attrs['mode'] = mode

if container.target_opset < 11:
if isinstance(pads, str):
raise ValueError("Dynamic pad is not supported for opset < 11.")
if value is not None:
attrs['value'] = value
if container.target_opset < 2:
Expand All @@ -514,9 +516,12 @@ def apply_pad(scope, input_name, output_name, container, operator_name=None, mod
op_version = 2
else:
op_version = 11
pads_name = scope.get_unique_variable_name(name + '_pads')
container.add_initializer(pads_name, onnx_proto.TensorProto.INT64, [len(pads)], pads)
inputs.append(pads_name)
if isinstance(pads, str):
inputs.append(pads)
else:
pads_name = scope.get_unique_variable_name(name + '_pads')
container.add_initializer(pads_name, onnx_proto.TensorProto.INT64, [len(pads)], pads)
inputs.append(pads_name)
if value is not None:
value_name = scope.get_unique_variable_name(name + '_value')
container.add_initializer(value_name, onnx_type, [], [value])
Expand Down Expand Up @@ -743,7 +748,7 @@ def apply_slice(scope, input_name, output_name, container, starts, ends,
op_version = 10
else:
op_version = 11
inputs = [input_name]
inputs = input_name if isinstance(input_name, list) else [input_name]
starts_name = scope.get_unique_variable_name('starts')
ends_name = scope.get_unique_variable_name('ends')
container.add_initializer(starts_name, onnx_proto.TensorProto.INT64,
Expand Down

0 comments on commit c452903

Please sign in to comment.