Skip to content

Commit 52ab2dc

Browse files
authored
Merge pull request #64 from mitmul/do-not-always-include-onnxruntime
Avoid importing testing module from the top level module directly
2 parents 53e31a5 + 81915d4 commit 52ab2dc

20 files changed

+67
-62
lines changed

examples/mxnet/export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import collections
55

6-
import numpy as np
7-
86
import chainer
97
import chainer.functions as F
8+
import numpy as np
9+
1010
import chainercv.links as C
1111
import mxnet
1212
import onnx_chainer

examples/nnvm/export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4+
import chainer
5+
import chainer.functions as F
46
import numpy as np
57
import onnx
68

7-
import chainer
8-
import chainer.functions as F
99
import chainercv.links as C
1010
import nnvm
1111
import onnx_chainer

examples/sample_rt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
import numpy as np
5-
import onnxruntime as rt
6-
74
import chainer
85
import chainer.links as L
6+
import numpy as np
7+
98
import onnx_chainer
9+
import onnxruntime as rt
1010
from chainercv import transforms
1111
from PIL import Image
1212

onnx_chainer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from onnx_chainer.export import convert_parameter # NOQA
22
from onnx_chainer.export import export # NOQA
33

4-
from onnx_chainer import testing # NOQA
4+
from onnx_chainer.export import MINIMUM_OPSET_VERSION # NOQA

onnx_chainer/export.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import collections
44
import warnings
55

6+
import chainer
67
import numpy
78
import onnx
89
from onnx.mapping import NP_TYPE_TO_TENSOR_TYPE
910

10-
import chainer
1111
from onnx_chainer import functions, mapping
12-
from onnx_chainer.testing import test_onnxruntime
1312

1413
try:
1514
from onnx import checker
@@ -20,6 +19,8 @@
2019
except ImportError:
2120
_available = False
2221

22+
MINIMUM_OPSET_VERSION = 7
23+
2324

2425
def _check_available():
2526
if not _available:
@@ -197,14 +198,14 @@ def export(model, args, filename=None, export_params=True,
197198

198199
if opset_version is None:
199200
opset_version = int(onnx.defs.onnx_opset_version())
200-
elif opset_version < test_onnxruntime.MINIMUM_OPSET_VERSION:
201+
elif opset_version < MINIMUM_OPSET_VERSION:
201202
warnings.warn(
202203
'ONNX-Chainer has been tested only with opset_version >= {m}. '
203204
'This is because ONNXRuntime supports only opset_version >= {m}. '
204205
'The ONNX file exported with your requested opset_version ({o}) '
205206
'may cause some problems because the converters used for the '
206207
'opset_version have not been tested.'.format(
207-
m=test_onnxruntime.MINIMUM_OPSET_VERSION,
208+
m=MINIMUM_OPSET_VERSION,
208209
o=opset_version)
209210
)
210211

onnx_chainer/functions/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import chainer
12
import numpy as np
23
from onnx import helper
34
from onnx.mapping import NP_TYPE_TO_TENSOR_TYPE
45

5-
import chainer
66
from onnx_chainer import mapping
77

88

onnx_chainer/functions/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import chainer
12
import numpy as np
23
from onnx import helper
34

4-
import chainer
5-
65

76
def convert_Convolution2DFunction(func, onnx_op_name, opset_version,
87
input_names, output_names, parameters):

onnx_chainer/functions/math.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import chainer
12
import numpy as np
23
from onnx import helper
34

4-
import chainer
5-
65

76
def convert_Add(func, onnx_op_name, opset_version, input_names, output_names,
87
parameters):

onnx_chainer/functions/noise.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from onnx import helper
2-
31
import chainer
2+
from onnx import helper
43

54

65
def convert_Dropout(

onnx_chainer/functions/normalization.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import sys
22

3-
from onnx import helper
4-
53
import chainer
4+
from onnx import helper
65

76

87
def convert_BatchNormalization(func, onnx_op_name, opset_version, input_names,

onnx_chainer/testing/test_mxnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import os
33
import warnings
44

5+
import chainer
56
import numpy as np
67
import onnx
78

8-
import chainer
99
import onnx_chainer
1010

1111
try:

onnx_chainer/testing/test_onnxruntime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import warnings
22

3+
import chainer
34
import numpy as np
45
import onnx
56

6-
import chainer
77
import onnx_chainer
88

99
try:

tests/functions_tests/test_activations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import unittest
22

3-
import numpy as np
4-
import onnx
5-
63
import chainer
74
import chainer.functions as F
85
import chainer.links as L
6+
import numpy as np
7+
import onnx
98
from chainer import testing
9+
10+
import onnx_chainer
1011
from onnx_chainer.testing import test_onnxruntime
1112

1213

@@ -42,7 +43,7 @@ def __call__(self, x):
4243

4344
def test_output(self):
4445
for opset_version in range(
45-
test_onnxruntime.MINIMUM_OPSET_VERSION,
46+
onnx_chainer.MINIMUM_OPSET_VERSION,
4647
onnx.defs.onnx_opset_version() + 1):
4748
test_onnxruntime.check_output(
4849
self.model, self.x, self.fn, opset_version=opset_version)
@@ -68,7 +69,7 @@ def __call__(self, x):
6869

6970
def test_output(self):
7071
for opset_version in range(
71-
test_onnxruntime.MINIMUM_OPSET_VERSION,
72+
onnx_chainer.MINIMUM_OPSET_VERSION,
7273
onnx.defs.onnx_opset_version() + 1):
7374
test_onnxruntime.check_output(
7475
self.model, self.x, self.fn, opset_version=opset_version)

tests/functions_tests/test_arrays.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import unittest
22

3-
import numpy as np
4-
import onnx
5-
63
import chainer
74
import chainer.functions as F
5+
import numpy as np
6+
import onnx
87
from chainer import testing
8+
9+
import onnx_chainer
910
from onnx_chainer.testing import test_onnxruntime
1011

1112

@@ -105,7 +106,7 @@ def __call__(self, x):
105106

106107
def test_output(self):
107108
for opset_version in range(
108-
test_onnxruntime.MINIMUM_OPSET_VERSION,
109+
onnx_chainer.MINIMUM_OPSET_VERSION,
109110
onnx.defs.onnx_opset_version() + 1):
110111
test_onnxruntime.check_output(
111112
self.model, self.x, self.fn, opset_version=opset_version)
@@ -133,7 +134,7 @@ def __call__(self, x1, x2):
133134

134135
def test_output(self):
135136
for opset_version in range(
136-
test_onnxruntime.MINIMUM_OPSET_VERSION,
137+
onnx_chainer.MINIMUM_OPSET_VERSION,
137138
onnx.defs.onnx_opset_version() + 1):
138139
test_onnxruntime.check_output(
139140
self.model, (self.x1, self.x2), self.fn,

tests/functions_tests/test_connections.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import unittest
22

3-
import numpy as np
4-
import onnx
5-
63
import chainer
74
import chainer.links as L
5+
import numpy as np
6+
import onnx
87
from chainer import testing
8+
9+
import onnx_chainer
910
from onnx_chainer.testing import test_onnxruntime
1011

1112

@@ -86,7 +87,7 @@ def __call__(self, x):
8687

8788
def test_output(self):
8889
for opset_version in range(
89-
test_onnxruntime.MINIMUM_OPSET_VERSION,
90+
onnx_chainer.MINIMUM_OPSET_VERSION,
9091
onnx.defs.onnx_opset_version() + 1):
9192
test_onnxruntime.check_output(
9293
self.model, self.x, self.fn, opset_version=opset_version)

tests/functions_tests/test_maths.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import unittest
22

3+
import chainer
34
import numpy as np
45
import onnx
5-
6-
import chainer
76
from chainer import testing
7+
8+
import onnx_chainer
89
from onnx_chainer.testing import test_onnxruntime
910

1011

@@ -47,7 +48,7 @@ def __call__(self, a):
4748

4849
def test_output(self):
4950
for opset_version in range(
50-
test_onnxruntime.MINIMUM_OPSET_VERSION,
51+
onnx_chainer.MINIMUM_OPSET_VERSION,
5152
onnx.defs.onnx_opset_version() + 1):
5253
test_onnxruntime.check_output(
5354
self.model, self.a, self.fn, opset_version=opset_version)
@@ -86,7 +87,7 @@ def __call__(self, a, b):
8687

8788
def test_output(self):
8889
for opset_version in range(
89-
test_onnxruntime.MINIMUM_OPSET_VERSION,
90+
onnx_chainer.MINIMUM_OPSET_VERSION,
9091
onnx.defs.onnx_opset_version() + 1):
9192
test_onnxruntime.check_output(
9293
self.model, self.x, self.fn, opset_version=opset_version)
@@ -123,7 +124,7 @@ def __call__(self, a, b, c):
123124

124125
def test_output(self):
125126
for opset_version in range(
126-
test_onnxruntime.MINIMUM_OPSET_VERSION,
127+
onnx_chainer.MINIMUM_OPSET_VERSION,
127128
onnx.defs.onnx_opset_version() + 1):
128129
test_onnxruntime.check_output(
129130
self.model, self.x, self.fn, opset_version=opset_version)

tests/functions_tests/test_noises.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import unittest
22

3-
import numpy as np
4-
import onnx
5-
63
import chainer
74
import chainer.functions as F
5+
import numpy as np
6+
import onnx
87
from chainer import testing
8+
9+
import onnx_chainer
910
from onnx_chainer.testing import test_onnxruntime
1011

1112

@@ -33,7 +34,7 @@ def __call__(self, x):
3334

3435
def test_output(self):
3536
for opset_version in range(
36-
test_onnxruntime.MINIMUM_OPSET_VERSION,
37+
onnx_chainer.MINIMUM_OPSET_VERSION,
3738
onnx.defs.onnx_opset_version() + 1):
3839
test_onnxruntime.check_output(
3940
self.model, self.x, self.fn, opset_version=opset_version)

tests/functions_tests/test_normalizations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import unittest
22

3-
import numpy as np
4-
import onnx
5-
63
import chainer
74
import chainer.functions as F
85
import chainer.links as L
6+
import numpy as np
7+
import onnx
98
from chainer import testing
9+
10+
import onnx_chainer
1011
from onnx_chainer.testing import test_onnxruntime
1112

1213

@@ -52,7 +53,7 @@ def __call__(self, x):
5253

5354
def test_output(self):
5455
for opset_version in range(
55-
test_onnxruntime.MINIMUM_OPSET_VERSION,
56+
onnx_chainer.MINIMUM_OPSET_VERSION,
5657
onnx.defs.onnx_opset_version() + 1):
5758
test_onnxruntime.check_output(
5859
self.model, self.x, self.fn, opset_version=opset_version)
@@ -83,7 +84,7 @@ def __call__(self, x):
8384

8485
def test_output(self):
8586
for opset_version in range(
86-
test_onnxruntime.MINIMUM_OPSET_VERSION,
87+
onnx_chainer.MINIMUM_OPSET_VERSION,
8788
onnx.defs.onnx_opset_version() + 1):
8889
test_onnxruntime.check_output(
8990
self.model, self.x, self.fn, opset_version=opset_version)

tests/functions_tests/test_poolings.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import unittest
22

3-
import numpy as np
4-
import onnx
5-
63
import chainer
74
import chainer.functions as F
5+
import numpy as np
6+
import onnx
87
from chainer import testing
8+
9+
import onnx_chainer
910
from onnx_chainer.testing import test_onnxruntime
1011

1112

@@ -35,7 +36,7 @@ def setUp(self):
3536

3637
def test_output(self):
3738
for opset_version in range(
38-
test_onnxruntime.MINIMUM_OPSET_VERSION,
39+
onnx_chainer.MINIMUM_OPSET_VERSION,
3940
onnx.defs.onnx_opset_version() + 1):
4041
test_onnxruntime.check_output(
4142
self.model, self.x, self.fn, opset_version=opset_version)
@@ -57,7 +58,7 @@ def setUp(self):
5758

5859
def test_output(self):
5960
for opset_version in range(
60-
test_onnxruntime.MINIMUM_OPSET_VERSION,
61+
onnx_chainer.MINIMUM_OPSET_VERSION,
6162
onnx.defs.onnx_opset_version() + 1):
6263
with self.assertRaises(RuntimeError):
6364
test_onnxruntime.check_output(

0 commit comments

Comments
 (0)