Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Failure when converting Dense layer with hard_sigmoid activation #718

Open
yrjok opened this issue May 28, 2021 · 0 comments
Open

Failure when converting Dense layer with hard_sigmoid activation #718

yrjok opened this issue May 28, 2021 · 0 comments

Comments

@yrjok
Copy link

yrjok commented May 28, 2021

Dear maintainers

When attempting to convert a model containing a Dense layer with a hard_sigmoid activation I stumbled upon the following error:

ValueError: Failed to create ONNX node. Undefined attribute pair (alpha, None)

The conversion seems works fine when using other activation functions however (e.g. relu, sigmoid).

Traceback:

Traceback (most recent call last):
  File "convert.py", line 10, in <module>
    onnx_model = keras2onnx.convert_keras(create_model())
  File "/home/yrjo/.local/lib/python3.7/site-packages/keras2onnx/main.py", line 83, in convert_keras
    return convert_topology(topology, name, doc_string, target_opset, channel_first_inputs)
  File "/home/yrjo/.local/lib/python3.7/site-packages/keras2onnx/topology.py", line 322, in convert_topology
    cvt(scope, operator, container)
  File "/home/yrjo/.local/lib/python3.7/site-packages/keras2onnx/ke2onnx/dense.py", line 43, in convert_keras_dense
    activation_process(scope, operator, container, biased_tensor_name)
  File "/home/yrjo/.local/lib/python3.7/site-packages/keras2onnx/ke2onnx/common.py", line 33, in activation_process
    apply_activation_function(scope, biased_tensor_name, operator.outputs[0].full_name, container)
  File "/home/yrjo/.local/lib/python3.7/site-packages/onnxconverter_common/onnx_ops.py", line 536, in apply_hard_sigmoid
    alpha=alpha, beta=beta)
  File "/home/yrjo/.local/lib/python3.7/site-packages/onnxconverter_common/onnx_ops.py", line 32, in _apply_unary_operation
    container.add_node(op_type, input_name, output_name, op_version=op_version, **attrs)
  File "/home/yrjo/.local/lib/python3.7/site-packages/keras2onnx/common/interim.py", line 123, in add_node
    raise ValueError('Failed to create ONNX node. Undefined attribute pair (%s, %s) found' % (k, v))
ValueError: Failed to create ONNX node. Undefined attribute pair (alpha, None) found

Steps to reproduce:

The following code reproduces the error:

import tensorflow as tf
import keras2onnx

def create_model():
    input_shape = (1, 256, 256, 3)
    inputs = tf.keras.layers.Input(input_shape)
    outputs = tf.keras.layers.Dense(1, activation=tf.keras.activations.hard_sigmoid)(inputs)
    return tf.keras.Model(inputs=inputs, outputs=outputs)

model = create_model()
onnx_model = keras2onnx.convert_keras(model)

Using

  • Python 3.7.8
  • Tensorflow 2.2.0
  • keras2onnx 1.7.0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant