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

Commit 1a19451

Browse files
authored
Add conv_add to unit test with constant input (#381)
* Add conv_add to unit test with constant input * Add conv_add to unit test with constant input
1 parent d63d091 commit 1a19451

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

keras2onnx/_builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def convert_tf_concat_v2(scope, operator, container):
594594
def convert_tf_const(scope, operator, container):
595595
node = operator.raw_operator
596596
np_arr = _cal_tensor_value(node.outputs[0])
597-
onnx_tensor = numpy_helper.from_array(np_arr, node.outputs[0].name)
597+
onnx_tensor = numpy_helper.from_array(np_arr, operator.outputs[0].onnx_name)
598598
container.add_initializer_from_tensor(onnx_tensor)
599599

600600

tests/test_layers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,20 @@ def test_dense_add(self):
737737
expected = model.predict(data)
738738
self.assertTrue(run_onnx_runtime('onnx_dense_add', onnx_model, data, expected, self.model_files))
739739

740+
@unittest.skipIf(is_tf2, "const is not initialized this way for tf2")
741+
def test_conv_add(self):
742+
input1 = Input(shape=(10, 10, 1))
743+
x1 = Conv2D(32, strides=(2, 2), kernel_size=3,
744+
bias_initializer=keras.initializers.RandomNormal(mean=0.0, stddev=0.05, seed=None))(input1)
745+
input2 = Input(tensor = tf.constant(np.random.rand(1, 32).astype(np.float32)))
746+
added = Add()([x1, input2])
747+
model = keras.models.Model(inputs=[input1, input2], outputs=added)
748+
onnx_model = keras2onnx.convert_keras(model, model.name)
749+
data = [np.random.rand(1, 10, 10, 1).astype(np.float32)]
750+
expected = model.predict(data)
751+
data += [np.random.rand(1, 32).astype(np.float32)]
752+
self.assertTrue(run_onnx_runtime('onnx_conv_add', onnx_model, data, expected, self.model_files))
753+
740754
def test_dense_softmax(self):
741755
data = self.asarray(1, 2, 3, 4)
742756
model = Sequential()

0 commit comments

Comments
 (0)