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

Commit e2ff3ee

Browse files
authored
Update unit test and coverage condition (#428)
1 parent 53a485a commit e2ff3ee

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

.azure-pipelines/linux-CI-keras-applications-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
- script: |
120120
pip install -e .
121121
python -c "import onnxruntime"
122-
coverage run --include=keras2onnx/* --omit=keras2onnx/ktf2onnx/* tests/test_layers.py
122+
coverage run --include=keras2onnx/* tests/test_layers.py
123123
coverage report -m
124124
coverage html
125125
displayName: 'coverage'

.azure-pipelines/win32-CI-keras-applications-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
call activate py$(python.version)
120120
pip install -e .
121121
echo Test onnxruntime installation... && python -c "import onnxruntime"
122-
coverage run --include=keras2onnx/* --omit=keras2onnx/ktf2onnx/* tests/test_layers.py
122+
coverage run --include=keras2onnx/* tests/test_layers.py
123123
coverage report -m
124124
coverage html
125125
displayName: 'coverage'

tests/test_layers.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,8 @@ def test_Bidirectional_seqlen_none(self):
16131613
expected = model.predict(x)
16141614
self.assertTrue(run_onnx_runtime(onnx_model.graph.name, onnx_model, x, expected, self.model_files))
16151615

1616-
@unittest.skipIf(is_tf2, 'TODO')
16171616
def test_rnn_state_passing(self):
1617+
K.clear_session()
16181618
for rnn_class in [SimpleRNN, GRU, LSTM]:
16191619
input1 = Input(shape=(None, 5))
16201620
input2 = Input(shape=(None, 5))
@@ -1771,38 +1771,43 @@ def test_recursive_and_shared_model(self):
17711771
expected = keras_model.predict(x)
17721772
self.assertTrue(run_onnx_runtime('recursive_and_shared', onnx_model, x, expected, self.model_files))
17731773

1774-
@unittest.skipIf(is_keras_older_than("2.2.4") or is_tf_keras or is_tf2,
1774+
@unittest.skipIf(is_keras_older_than("2.2.4"),
17751775
"Low keras version is not supported.")
17761776
def test_shared_model_2(self):
17771777
K.set_learning_phase(0)
17781778

1779-
def _conv_layer(input, filters, kernel_size, strides=1, dilation_rate=1):
1779+
def _conv_layer(input, filters, kernel_size, relu_flag=False, strides=1, dilation_rate=1):
17801780
padding = 'same' if strides == 1 else 'valid'
17811781
if strides > 1:
17821782
input = ZeroPadding2D(((0, 1), (0, 1)), data_format=K.image_data_format())(input)
17831783
x = Conv2D(filters=filters, kernel_size=kernel_size, strides=strides,
17841784
padding=padding, use_bias=False, dilation_rate=dilation_rate)(input)
17851785
ch_axis = 1 if K.image_data_format() == 'channels_first' else -1
17861786
x = BatchNormalization(axis=ch_axis)(x)
1787-
return ReLU()(x)
1787+
if relu_flag:
1788+
return ReLU()(x)
1789+
else:
1790+
return x
17881791

1789-
def _model():
1792+
def _model(relu_flag=False):
17901793
input = Input(shape=(3, 320, 320), name='input_1')
1791-
x = _conv_layer(input, 16, 3)
1794+
x = _conv_layer(input, 16, 3, relu_flag)
17921795
return Model(inputs=input, outputs=x, name='backbone')
17931796

1794-
input = Input(shape=(3, 320, 320), name='input')
1795-
backbone = _model()
1796-
x = backbone(input)
1797-
x = _conv_layer(x, 16, 3)
1798-
model = Model(inputs=[input], outputs=[x])
1797+
relu_flags = [False] if is_tf2 or is_tf_keras else [True, False]
1798+
for relu_flag_ in relu_flags:
1799+
input = Input(shape=(3, 320, 320), name='input')
1800+
backbone = _model(relu_flag_)
1801+
x = backbone(input)
1802+
x = _conv_layer(x, 16, 3)
1803+
model = Model(inputs=[input], outputs=[x])
17991804

1800-
onnx_model = keras2onnx.convert_keras(model, model.name)
1801-
x = np.random.rand(2, 3, 320, 320).astype(np.float32)
1802-
expected = model.predict(x)
1803-
self.assertTrue(run_onnx_runtime(onnx_model.graph.name, onnx_model, x, expected, self.model_files))
1805+
onnx_model = keras2onnx.convert_keras(model, model.name)
1806+
x = np.random.rand(2, 3, 320, 320).astype(np.float32)
1807+
expected = model.predict(x)
1808+
self.assertTrue(run_onnx_runtime(onnx_model.graph.name, onnx_model, x, expected, self.model_files))
18041809

1805-
@unittest.skipIf(is_keras_older_than("2.2.4") or is_tf_keras,
1810+
@unittest.skipIf(is_keras_older_than("2.2.4"),
18061811
"ReLU support requires keras 2.2.4 or later.")
18071812
def test_shared_model_3(self):
18081813
def _bottleneck(x, filters, activation, strides, block_id):
@@ -1851,7 +1856,8 @@ def convnet_7(input_shape, activation):
18511856
x = _bottleneck(x, filters=32, strides=2, activation=activation, block_id=2)
18521857
return Model(inputs=input, outputs=x, name='convnet_7')
18531858

1854-
for activation in ['relu', 'leaky']:
1859+
activation_list = ['leaky'] if is_tf2 or is_tf_keras else ['relu', 'leaky']
1860+
for activation in activation_list:
18551861
model = convnet_7(input_shape=(3, 96, 128), activation=activation)
18561862
onnx_model = keras2onnx.convert_keras(model, model.name)
18571863
x = np.random.rand(1, 3, 96, 128).astype(np.float32)

0 commit comments

Comments
 (0)