Skip to content

Commit 6691850

Browse files
authored
Skip the blob failed model tests (#1806)
Signed-off-by: hwangdeyu [email protected] Co-authored-by: fatcat-z [email protected]
1 parent f1ee0b4 commit 6691850

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

tests/keras2onnx_applications/nightly_build/test_transformers.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
import os
4-
import sys
4+
from os.path import dirname, abspath
55
import unittest
6-
import mock_keras2onnx
6+
import sys
7+
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
8+
79
import json
810
import urllib.request
911
import pickle
10-
from os.path import dirname, abspath
11-
from mock_keras2onnx.proto import keras
1212
import numpy as np
1313
import tensorflow as tf
14-
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
1514

16-
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
17-
from test_utils import run_onnx_runtime
18-
from mock_keras2onnx.proto import is_tensorflow_older_than
15+
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
16+
import mock_keras2onnx
17+
from mock_keras2onnx.proto import keras, is_tensorflow_older_than
18+
from test_utils import is_bloburl_access, run_onnx_runtime
1919

2020
enable_full_transformer_test = False
2121
if os.environ.get('ENABLE_FULL_TRANSFORMER_TEST', '0') != '0':
2222
enable_transformer_test = True
2323

24+
CONVERTER_TRANSFERMER_PATH = r'https://lotus.blob.core.windows.net/converter-models/transformer_tokenizer/'
25+
2426

2527
@unittest.skipIf(is_tensorflow_older_than('2.1.0'),
2628
"Transformers conversion need tensorflow 2.1.0+")
29+
@unittest.skipIf(not is_bloburl_access(CONVERTER_TRANSFERMER_PATH), "Model blob url can't access.")
2730
class TestTransformers(unittest.TestCase):
2831

2932
text_str = 'The quick brown fox jumps over lazy dog.'

tests/keras2onnx_applications/nightly_build/test_yolov3.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
import os
4-
import sys
5-
import unittest
6-
import mock_keras2onnx
7-
import onnx
8-
import numpy as np
94
from os.path import dirname, abspath
5+
import numpy as np
6+
import unittest
7+
import sys
108
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
11-
from keras.models import load_model
9+
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../yolov3'))
1210

11+
from keras.models import load_model
12+
import onnx
1313
import urllib.request
14+
from yolov3 import YOLO, convert_model
15+
16+
from distutils.version import StrictVersion
17+
import mock_keras2onnx
18+
from test_utils import is_bloburl_access
19+
20+
1421
YOLOV3_WEIGHTS_PATH = r'https://lotus.blob.core.windows.net/converter-models/yolov3.h5'
1522
model_file_name = 'yolov3.h5'
1623
YOLOV3_TINY_WEIGHTS_PATH = r'https://lotus.blob.core.windows.net/converter-models/yolov3-tiny.h5'
1724
tiny_model_file_name = 'yolov3-tiny.h5'
1825

19-
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../yolov3'))
20-
from yolov3 import YOLO, convert_model
21-
22-
from distutils.version import StrictVersion
23-
2426
working_path = os.path.abspath(os.path.dirname(__file__))
2527
tmp_path = os.path.join(working_path, 'temp')
2628

@@ -45,6 +47,8 @@ def post_compute(self, all_boxes, all_scores, indices):
4547

4648
@unittest.skipIf(StrictVersion(onnx.__version__.split('-')[0]) < StrictVersion("1.5.0"),
4749
"NonMaxSuppression op is not supported for onnx < 1.5.0.")
50+
@unittest.skipIf(not is_bloburl_access(YOLOV3_WEIGHTS_PATH) or not is_bloburl_access(YOLOV3_TINY_WEIGHTS_PATH),
51+
"Model blob url can't access.")
4852
def test_yolov3(self):
4953
img_path = os.path.join(os.path.dirname(__file__), '../data', 'street.jpg')
5054
yolo3_yolo3_dir = os.path.join(os.path.dirname(__file__), '../../../keras-yolo3/yolo3')

tests/keras2onnx_unit_tests/test_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import mock_keras2onnx
88
from mock_keras2onnx.proto import keras, is_keras_older_than
99
from mock_keras2onnx.proto.tfcompat import is_tf2
10-
#from mock_keras2onnx.common.onnx_ops import apply_identity, OnnxOperatorBuilder
1110
import time
1211
import json
12+
import urllib
1313

1414
working_path = os.path.abspath(os.path.dirname(__file__))
1515
tmp_path = os.path.join(working_path, 'temp')
@@ -282,3 +282,11 @@ def run_image(model, model_files, img_path, model_name='onnx_conversion', rtol=1
282282
onnx_model = mock_keras2onnx.convert_keras(model, model.name)
283283
res = run_onnx_runtime(model_name, onnx_model, x, preds, model_files, rtol=rtol, atol=atol, compare_perf=compare_perf)
284284
return res, msg
285+
286+
287+
def is_bloburl_access(url):
288+
try:
289+
response = urllib.request.urlopen(url)
290+
return response.getcode() == 200
291+
except urllib.error.URLError:
292+
return False

0 commit comments

Comments
 (0)