Skip to content

Commit 1660689

Browse files
Make keras2onnx tests deterministic (#1571)
Signed-off-by: Tom Wildenhain <[email protected]> Co-authored-by: Guenther Schmuelling <[email protected]>
1 parent 070812f commit 1660689

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

keras2onnx_tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import pytest
55

6+
import numpy as np
7+
68
from mock_keras2onnx.proto import keras
79
from test_utils import run_onnx_runtime
810

@@ -11,6 +13,7 @@
1113

1214
@pytest.fixture(scope='function')
1315
def runner():
16+
np.random.seed(42)
1417
model_files = []
1518

1619
def runner_func(*args, **kwargs):
@@ -23,7 +26,6 @@ def runner_func(*args, **kwargs):
2326

2427
# Provide wrapped run_onnx_runtime function
2528
yield runner_func
26-
2729
# Remove model files
2830
for fl in model_files:
2931
os.remove(fl)

keras2onnx_tests/test_layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ def test_dense_add(runner):
10301030
def test_conv_add(runner):
10311031
input1 = Input(shape=(10, 10, 1))
10321032
x1 = Conv2D(32, strides=(2, 2), kernel_size=3,
1033-
bias_initializer=keras.initializers.RandomNormal(mean=0.0, stddev=0.05, seed=None))(input1)
1033+
bias_initializer=keras.initializers.RandomNormal(mean=0.0, stddev=0.05, seed=42))(input1)
10341034
input2 = Input(tensor=tf.constant(np.random.rand(1, 32).astype(np.float32)))
10351035
added = Add()([x1, input2])
10361036
model = keras.models.Model(inputs=[input1, input2], outputs=added)

0 commit comments

Comments
 (0)