Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace distutils.version with packaging.version namespace. #2056

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/keras2onnx_applications/nightly_build/test_acgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from os.path import dirname, abspath
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
from test_utils import run_onnx_runtime
from distutils.version import StrictVersion
from packaging.version import Version

Activation = keras.layers.Activation
BatchNormalization = keras.layers.BatchNormalization
Expand Down Expand Up @@ -133,7 +133,7 @@ def tearDown(self):
for fl in self.model_files:
os.remove(fl)

@unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.5.0"),
@unittest.skipIf(Version(onnx.__version__) < Version("1.5.0"),
"Not supported before onnx 1.5.0")
def test_ACGAN(self):
keras_model = ACGAN().combined
Expand Down
4 changes: 2 additions & 2 deletions tests/keras2onnx_applications/nightly_build/test_mask_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
keras.backend.clear_session()
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../mask_rcnn/'))
from mask_rcnn import model
from distutils.version import StrictVersion
from packaging.version import Version

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

@unittest.skipIf(StrictVersion(onnx.__version__.split('-')[0]) < StrictVersion("1.6.0"),
@unittest.skipIf(Version(onnx.__version__.split('-')[0]) < Version("1.6.0"),
"Mask-rcnn conversion needs contrib op for onnx < 1.6.0.")
def test_mask_rcnn(self):
set_converter('CropAndResize', convert_tf_crop_and_resize)
Expand Down
4 changes: 2 additions & 2 deletions tests/keras2onnx_applications/nightly_build/test_unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os.path import dirname, abspath
from mock_keras2onnx.proto import keras, is_keras_older_than
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from distutils.version import StrictVersion
from packaging.version import Version

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

@unittest.skipIf(StrictVersion(onnxruntime.__version__.split('-')[0]) < StrictVersion('1.7.0'),
@unittest.skipIf(Version(onnxruntime.__version__.split('-')[0]) < Version('1.7.0'),
"ConvTranspose stride > 1 is fixed in onnxruntime 1.7.0.")
def test_unet_3(self):
# From https://github.com/yu4u/noise2noise/blob/master/model.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mock_keras2onnx.proto import keras, is_keras_older_than
from keras.applications.vgg16 import VGG16
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from distutils.version import StrictVersion
from packaging.version import Version

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

@unittest.skipIf(StrictVersion(onnxruntime.__version__.split('-')[0]) < StrictVersion('1.7.0'),
@unittest.skipIf(Version(onnxruntime.__version__.split('-')[0]) < Version('1.7.0'),
"ConvTranspose stride > 1 is fixed in onnxruntime 1.7.0.")
def test_unet_plus_plus(self):
backbone_name = 'vgg16'
Expand Down
4 changes: 2 additions & 2 deletions tests/keras2onnx_applications/nightly_build/test_yolov3.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import urllib.request
from yolov3 import YOLO, convert_model

from distutils.version import StrictVersion
from packaging.version import Version
import mock_keras2onnx
from test_utils import is_bloburl_access

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

@unittest.skipIf(StrictVersion(onnx.__version__.split('-')[0]) < StrictVersion("1.5.0"),
@unittest.skipIf(Version(onnx.__version__.split('-')[0]) < Version("1.5.0"),
"NonMaxSuppression op is not supported for onnx < 1.5.0.")
@unittest.skipIf(not is_bloburl_access(YOLOV3_WEIGHTS_PATH) or not is_bloburl_access(YOLOV3_TINY_WEIGHTS_PATH),
"Model blob url can't access.")
Expand Down
4 changes: 2 additions & 2 deletions tests/keras2onnx_unit_tests/mock_keras2onnx/proto/tfcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os
import tensorflow as _tf

from distutils.version import StrictVersion
from packaging.version import Version

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


def normalize_tensor_shape(tensor_shape):
Expand Down
4 changes: 2 additions & 2 deletions tests/keras2onnx_unit_tests/test_cgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from mock_keras2onnx.proto import keras, is_tf_keras, is_tensorflow_older_than
from tf2onnx.keras2onnx_api import convert_keras
from distutils.version import StrictVersion
from packaging.version import Version

Activation = keras.layers.Activation
BatchNormalization = keras.layers.BatchNormalization
Expand Down Expand Up @@ -116,7 +116,7 @@ def build_discriminator(self):


@pytest.mark.skipif(mock_keras2onnx.proto.tfcompat.is_tf2 and is_tf_keras, reason="Tensorflow 1.x only tests.")
@pytest.mark.skipif(is_tf_keras and StrictVersion(tf.__version__.split('-')[0]) < StrictVersion("1.14.0"),
@pytest.mark.skipif(is_tf_keras and Version(tf.__version__.split('-')[0]) < Version("1.14.0"),
reason="Not supported before tensorflow 1.14.0 for tf_keras")
@pytest.mark.skipif(mock_keras2onnx.proto.tfcompat.is_tf2 and is_tensorflow_older_than('2.2'),
reason="Variable freezing fails to replace ResourceGather op")
Expand Down
4 changes: 2 additions & 2 deletions tests/keras2onnx_unit_tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,8 @@ def test_conv1d_padding(conv1_runner):
test_causal = False
if is_tf_keras:
import tensorflow
from distutils.version import StrictVersion
if StrictVersion(tensorflow.__version__.split('-')[0]) >= StrictVersion('1.12.0'):
from packaging.version import Version
if Version(tensorflow.__version__.split('-')[0]) >= Version('1.12.0'):
test_causal = True
else:
test_causal = True
Expand Down