Skip to content

Commit 0411a75

Browse files
authored
Merge pull request #2056 from fatcat-z/use_packaging_version
Replace distutils.version with packaging.version namespace.
2 parents c60c5ee + 3645e64 commit 0411a75

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

tests/keras2onnx_applications/nightly_build/test_acgan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from os.path import dirname, abspath
1111
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
1212
from test_utils import run_onnx_runtime
13-
from distutils.version import StrictVersion
13+
from packaging.version import Version
1414

1515
Activation = keras.layers.Activation
1616
BatchNormalization = keras.layers.BatchNormalization
@@ -133,7 +133,7 @@ def tearDown(self):
133133
for fl in self.model_files:
134134
os.remove(fl)
135135

136-
@unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.5.0"),
136+
@unittest.skipIf(Version(onnx.__version__) < Version("1.5.0"),
137137
"Not supported before onnx 1.5.0")
138138
def test_ACGAN(self):
139139
keras_model = ACGAN().combined

tests/keras2onnx_applications/nightly_build/test_mask_rcnn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
keras.backend.clear_session()
2222
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../mask_rcnn/'))
2323
from mask_rcnn import model
24-
from distutils.version import StrictVersion
24+
from packaging.version import Version
2525

2626
working_path = os.path.abspath(os.path.dirname(__file__))
2727
tmp_path = os.path.join(working_path, 'temp')
@@ -36,7 +36,7 @@ def tearDown(self):
3636
for fl in self.model_files:
3737
os.remove(fl)
3838

39-
@unittest.skipIf(StrictVersion(onnx.__version__.split('-')[0]) < StrictVersion("1.6.0"),
39+
@unittest.skipIf(Version(onnx.__version__.split('-')[0]) < Version("1.6.0"),
4040
"Mask-rcnn conversion needs contrib op for onnx < 1.6.0.")
4141
def test_mask_rcnn(self):
4242
set_converter('CropAndResize', convert_tf_crop_and_resize)

tests/keras2onnx_applications/nightly_build/test_unet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from os.path import dirname, abspath
99
from mock_keras2onnx.proto import keras, is_keras_older_than
1010
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
11-
from distutils.version import StrictVersion
11+
from packaging.version import Version
1212

1313
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
1414
from test_utils import run_image
@@ -126,7 +126,7 @@ def test_unet_2(self):
126126
res = run_image(model, self.model_files, img_path, color_mode="grayscale", target_size=(img_rows, img_cols))
127127
self.assertTrue(*res)
128128

129-
@unittest.skipIf(StrictVersion(onnxruntime.__version__.split('-')[0]) < StrictVersion('1.7.0'),
129+
@unittest.skipIf(Version(onnxruntime.__version__.split('-')[0]) < Version('1.7.0'),
130130
"ConvTranspose stride > 1 is fixed in onnxruntime 1.7.0.")
131131
def test_unet_3(self):
132132
# From https://github.com/yu4u/noise2noise/blob/master/model.py

tests/keras2onnx_applications/nightly_build/test_unet_plus_plus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from mock_keras2onnx.proto import keras, is_keras_older_than
1010
from keras.applications.vgg16 import VGG16
1111
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
12-
from distutils.version import StrictVersion
12+
from packaging.version import Version
1313

1414
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
1515
from test_utils import run_image
@@ -102,7 +102,7 @@ def tearDown(self):
102102
for fl in self.model_files:
103103
os.remove(fl)
104104

105-
@unittest.skipIf(StrictVersion(onnxruntime.__version__.split('-')[0]) < StrictVersion('1.7.0'),
105+
@unittest.skipIf(Version(onnxruntime.__version__.split('-')[0]) < Version('1.7.0'),
106106
"ConvTranspose stride > 1 is fixed in onnxruntime 1.7.0.")
107107
def test_unet_plus_plus(self):
108108
backbone_name = 'vgg16'

tests/keras2onnx_applications/nightly_build/test_yolov3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import urllib.request
1414
from yolov3 import YOLO, convert_model
1515

16-
from distutils.version import StrictVersion
16+
from packaging.version import Version
1717
import mock_keras2onnx
1818
from test_utils import is_bloburl_access
1919

@@ -45,7 +45,7 @@ def post_compute(self, all_boxes, all_scores, indices):
4545
out_boxes.append(all_boxes[idx_1])
4646
return [out_boxes, out_scores, out_classes]
4747

48-
@unittest.skipIf(StrictVersion(onnx.__version__.split('-')[0]) < StrictVersion("1.5.0"),
48+
@unittest.skipIf(Version(onnx.__version__.split('-')[0]) < Version("1.5.0"),
4949
"NonMaxSuppression op is not supported for onnx < 1.5.0.")
5050
@unittest.skipIf(not is_bloburl_access(YOLOV3_WEIGHTS_PATH) or not is_bloburl_access(YOLOV3_TINY_WEIGHTS_PATH),
5151
"Model blob url can't access.")

tests/keras2onnx_unit_tests/mock_keras2onnx/proto/tfcompat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44
import tensorflow as _tf
55

6-
from distutils.version import StrictVersion
6+
from packaging.version import Version
77

8-
is_tf2 = StrictVersion(_tf.__version__.split('-')[0]) >= StrictVersion('2.0.0')
8+
is_tf2 = Version(_tf.__version__.split('-')[0]) >= Version("2.0.0")
99

1010

1111
def normalize_tensor_shape(tensor_shape):

tests/keras2onnx_unit_tests/test_cgan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
from mock_keras2onnx.proto import keras, is_tf_keras, is_tensorflow_older_than
88
from tf2onnx.keras2onnx_api import convert_keras
9-
from distutils.version import StrictVersion
9+
from packaging.version import Version
1010

1111
Activation = keras.layers.Activation
1212
BatchNormalization = keras.layers.BatchNormalization
@@ -116,7 +116,7 @@ def build_discriminator(self):
116116

117117

118118
@pytest.mark.skipif(mock_keras2onnx.proto.tfcompat.is_tf2 and is_tf_keras, reason="Tensorflow 1.x only tests.")
119-
@pytest.mark.skipif(is_tf_keras and StrictVersion(tf.__version__.split('-')[0]) < StrictVersion("1.14.0"),
119+
@pytest.mark.skipif(is_tf_keras and Version(tf.__version__.split('-')[0]) < Version("1.14.0"),
120120
reason="Not supported before tensorflow 1.14.0 for tf_keras")
121121
@pytest.mark.skipif(mock_keras2onnx.proto.tfcompat.is_tf2 and is_tensorflow_older_than('2.2'),
122122
reason="Variable freezing fails to replace ResourceGather op")

tests/keras2onnx_unit_tests/test_layers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,8 @@ def test_conv1d_padding(conv1_runner):
11391139
test_causal = False
11401140
if is_tf_keras:
11411141
import tensorflow
1142-
from distutils.version import StrictVersion
1143-
if StrictVersion(tensorflow.__version__.split('-')[0]) >= StrictVersion('1.12.0'):
1142+
from packaging.version import Version
1143+
if Version(tensorflow.__version__.split('-')[0]) >= Version('1.12.0'):
11441144
test_causal = True
11451145
else:
11461146
test_causal = True

0 commit comments

Comments
 (0)