Skip to content

Commit 610feae

Browse files
authored
Merge branch 'master' into fix_instance_norm
2 parents 24877e8 + c63d435 commit 610feae

23 files changed

+808
-586
lines changed

doc/API.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _params_:
2020
`model` : The ONNX model to be converted.
2121

2222

23-
`device` : The device to execute this model on.
23+
`device` : The device to execute this model on. It can be either CPU (default) or CUDA.
2424

2525

2626
`strict` : Whether to enforce semantic equivalence between the original model

doc/CLI.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ optional arguments:
4040
Output directory.
4141
4242
backend arguments (onnx -> tf):
43-
--device DEVICE The device to execute this model on. (from
44-
onnx_tf.backend.prepare)
43+
--device DEVICE The device to execute this model on. It can be either
44+
CPU (default) or CUDA. (from onnx_tf.backend.prepare)
4545
--strict STRICT Whether to enforce semantic equivalence between the
4646
original model and the converted tensorflow model,
4747
defaults to True (yes, enforce semantic equivalence).

doc/support_status.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# ONNX-Tensorflow Support Status
22
|||
33
|-:|:-|
4-
|ONNX-Tensorflow Version|Master ( commit id: 6bfd631e0daedbc773b76636a5ea19e77a4b63ed )|
5-
|ONNX Version|Master ( commit id: b2ed660d0a065b8346816f2c3a95d79ca79b88c9 )|
6-
|Tensorflow Version|v2.3.0|
4+
|ONNX-Tensorflow Version|Master ( commit id: f64afb48034af7121341f4ba5d6f56e275c5aedb )|
5+
|ONNX Version|Master ( commit id: a7a0fec7f25cae567429af62b7eaaee1c3f0e247 )|
6+
|Tensorflow Version|v2.3.1|
77

88
Notes:
99
* Values that are new or updated from a previous opset version are in bold.
@@ -51,7 +51,7 @@ Notes:
5151
|Div|**1**|1|1|1|1|**6**|**7**|7|7|7|7|7|**13**:small_red_triangle:|Div|
5252
|Dropout|**1**|1|1|1|1|**6**|**7**|7|7|**10**|10|**12**|**13**|Dropout|
5353
|DynamicQuantizeLinear|-|-|-|-|-|-|-|-|-|-|**11**|11|11|DynamicQuantizeLinear|
54-
|Einsum|-|-|-|-|-|-|-|-|-|-|-|**12**:small_red_triangle:|12:small_red_triangle:|Einsum|
54+
|Einsum|-|-|-|-|-|-|-|-|-|-|-|**12**|12|Einsum|
5555
|Elu|**1**|1|1|1|1|**6**|6|6|6|6|6|6|6|Elu|
5656
|Equal|**1**|1|1|1|1|1|**7**|7|7|7|**11**|11|**13**|Equal|
5757
|Erf|-|-|-|-|-|-|-|-|**9**|9|9|9|**13**|Erf|
@@ -72,11 +72,11 @@ Notes:
7272
|GreaterOrEqual|-|-|-|-|-|-|-|-|-|-|-|**12**|12|GreaterOrEqual|
7373
|HardSigmoid|**1**|1|1|1|1|**6**|6|6|6|6|6|6|6|HardSigmoid|
7474
|Hardmax|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|Hardmax|
75-
|Identity|**1**|1|1|1|1|1|1|1|1|1|1|1|**13**:small_red_triangle:|Identity|
75+
|Identity|**1**|1|1|1|1|1|1|1|1|1|1|1|**13**|Identity|
7676
|If|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**|If|
7777
|InstanceNormalization|**1**|1|1|1|1|**6**|6|6|6|6|6|6|6|InstanceNormalization|
7878
|IsInf|-|-|-|-|-|-|-|-|-|**10**|10|10|10|IsInf|
79-
|IsNaN|-|-|-|-|-|-|-|-|**9**|9|9|9|**13**:small_red_triangle:|IsNaN|
79+
|IsNaN|-|-|-|-|-|-|-|-|**9**|9|9|9|**13**|IsNaN|
8080
|LRN|**1**|1|1|1|1|1|1|1|1|1|1|1|**13**|LRN|
8181
|LSTM|**1**:small_orange_diamond:|1:small_orange_diamond:|1:small_orange_diamond:|1:small_orange_diamond:|1:small_orange_diamond:|1:small_orange_diamond:|**7**:small_orange_diamond:|7:small_orange_diamond:|7:small_orange_diamond:|7:small_orange_diamond:|7:small_orange_diamond:|7:small_orange_diamond:|7:small_orange_diamond:|LSTM|
8282
|LeakyRelu|**1**|1|1|1|1|**6**|6|6|6|6|6|6|6|LeakyRelu|
@@ -100,7 +100,7 @@ Notes:
100100
|Mul|**1**|1|1|1|1|**6**|**7**|7|7|7|7|7|**13**|Mul|
101101
|Multinomial|-|-|-|-|-|-|**7**:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|Multinomial|
102102
|Neg|**1**|1|1|1|1|**6**|6|6|6|6|6|6|**13**|Neg|
103-
|NegativeLogLikelihoodLoss|-|-|-|-|-|-|-|-|-|-|-|**12**:small_red_triangle:|12:small_red_triangle:|NegativeLogLikelihoodLoss|
103+
|NegativeLogLikelihoodLoss|-|-|-|-|-|-|-|-|-|-|-|**12**:small_red_triangle:|**13**:small_red_triangle:|NegativeLogLikelihoodLoss|
104104
|NonMaxSuppression|-|-|-|-|-|-|-|-|-|**10**|**11**|11|11|NonMaxSuppression|
105105
|NonZero|-|-|-|-|-|-|-|-|**9**|9|9|9|**13**:small_red_triangle:|NonZero|
106106
|Not|**1**|1|1|1|1|1|1|1|1|1|1|1|1|Not|
@@ -123,10 +123,10 @@ Notes:
123123
|ReduceL2|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|ReduceL2|
124124
|ReduceLogSum|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|ReduceLogSum|
125125
|ReduceLogSumExp|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|ReduceLogSumExp|
126-
|ReduceMax|**1**|1|1|1|1|1|1|1|1|1|**11**|**12**|**13**:small_red_triangle:|ReduceMax|
127-
|ReduceMean|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|ReduceMean|
128-
|ReduceMin|**1**|1|1|1|1|1|1|1|1|1|**11**|**12**|**13**:small_red_triangle:|ReduceMin|
129-
|ReduceProd|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|ReduceProd|
126+
|ReduceMax|**1**|1|1|1|1|1|1|1|1|1|**11**|**12**|**13**|ReduceMax|
127+
|ReduceMean|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**|ReduceMean|
128+
|ReduceMin|**1**|1|1|1|1|1|1|1|1|1|**11**|**12**|**13**|ReduceMin|
129+
|ReduceProd|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**|ReduceProd|
130130
|ReduceSum|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|ReduceSum|
131131
|ReduceSumSquare|**1**|1|1|1|1|1|1|1|1|1|**11**|11|**13**:small_red_triangle:|ReduceSumSquare|
132132
|Relu|**1**|1|1|1|1|**6**|6|6|6|6|6|6|**13**:small_red_triangle:|Relu|
@@ -179,7 +179,7 @@ Notes:
179179
|Where|-|-|-|-|-|-|-|-|**9**|9|9|9|9|Where|
180180
|Xor|**1**|1|1|1|1|1|**7**|7|7|7|7|7|7|Xor|
181181

182-
ONNX-TF Supported Operators / ONNX Operators: 105 / 162
182+
ONNX-TF Supported Operators / ONNX Operators: 118 / 162
183183

184184
Notes:
185185
1. Cast: Cast string to data types other than float32/float64/int32/int64 is not supported in Tensorflow

onnx_tf/backend.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def prepare(cls,
4949
the converted representation.
5050
5151
:param model: The ONNX model to be converted.
52-
:param device: The device to execute this model on.
52+
:param device: The device to execute this model on. It can be either CPU (default) or CUDA.
5353
:param strict: Whether to enforce semantic equivalence between the original model
5454
and the converted tensorflow model, defaults to True (yes, enforce semantic equivalence).
5555
Changing to False is strongly discouraged.
@@ -65,6 +65,7 @@ def prepare(cls,
6565
common.logger.setLevel(logging_level)
6666
common.logger.handlers[0].setLevel(logging_level)
6767
common.sys_config.auto_cast = auto_cast
68+
common.sys_config.device = device
6869

6970
return cls.onnx_model_to_tensorflow_rep(model, strict, **kwargs)
7071

@@ -184,6 +185,7 @@ def __call__(self, **input_dict):
184185
return cls._onnx_node_to_tensorflow_op(self.node, input_dict)
185186

186187
super(TensorflowBackend, cls).run_node(node, inputs, device)
188+
common.sys_config.device = device
187189

188190
node = OnnxNode(node)
189191
input_tensors = []

onnx_tf/backend_tf_module.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def __init__(self, handlers, opset, strict, graph_def, backend):
1212
self.graph_def = graph_def
1313
self.backend = backend
1414
self.outputs = []
15+
self.initializer_dict = self._get_initializer_from_graph_and_subgraphs(
16+
self.graph_def, dict())
1517

1618
# get initializer from the main graph and all subgraphs in loop or if or scan
1719
# into tensor_dict
@@ -37,8 +39,8 @@ def _get_initializer_from_graph_and_subgraphs(self, graph, graph_tensor_dict):
3739

3840
@tf.function
3941
def gen_tensor_dict(self, input_dict):
40-
tensor_dict = self._get_initializer_from_graph_and_subgraphs(
41-
self.graph_def, dict(input_dict))
42+
tensor_dict = dict(input_dict)
43+
tensor_dict.update(self.initializer_dict)
4244

4345
for node in self.graph_def.node:
4446
onnx_node = OnnxNode(node)
@@ -54,8 +56,8 @@ def gen_tensor_dict(self, input_dict):
5456

5557
@tf.function
5658
def __call__(self, **kwargs):
57-
tensor_dict = self._get_initializer_from_graph_and_subgraphs(
58-
self.graph_def, kwargs)
59+
tensor_dict = kwargs
60+
tensor_dict.update(self.initializer_dict)
5961

6062
for node in self.graph_def.node:
6163
onnx_node = OnnxNode(node)

onnx_tf/common/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SysConfig:
2828

2929
def __init__(self):
3030
self.auto_cast = False
31+
self.device = 'CPU'
32+
3133

3234

3335
sys_config = SysConfig()
@@ -160,7 +162,7 @@ def get_data_format(x_rank):
160162
sp_dim_string = "".join(reversed(sp_dim_lst))
161163
storage_format = "NC" + sp_dim_string
162164

163-
if supports_device("CUDA"):
165+
if sys_config.device == "CUDA":
164166
compute_format = "NC" + sp_dim_string
165167
else:
166168
compute_format = "N" + sp_dim_string + "C"
@@ -169,7 +171,6 @@ def get_data_format(x_rank):
169171

170172
def supports_device(device):
171173
""" Check if support target device.
172-
173174
:param device: CUDA or CPU.
174175
:return: If supports.
175176
"""

onnx_tf/common/pooling_helper.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def py_pool(input, kernel_shape, strides=None, dilations=None,
158158

159159
def _loop_over_output(batch, channel):
160160
dims = [range(output_sp_shape[d]) for d in range(spatial_size)]
161+
image_size = 1
162+
for d in input_shape[2:]:
163+
image_size *= d
161164
for counters in itertools.product(*dims):
162165
input_ranges = []
163166
for dim in range(spatial_size):
@@ -189,7 +192,10 @@ def _loop_over_output(batch, channel):
189192
else:
190193
if val > maxval:
191194
maxval = val
192-
ind = 0
195+
# batch_offset = batch * C * image_size
196+
# channel_offset = channel * image_size
197+
# ind = batch_offset + channel_offset
198+
ind = image_size * (batch * input_shape[1] + channel)
193199
for i in range(spatial_size):
194200
coef = 1
195201
for j in range(i+1, spatial_size):

onnx_tf/handlers/backend/conv_mixin.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import tensorflow as tf
22

3+
from onnx_tf.common import exception
34
from onnx_tf.common import get_data_format
45
from onnx_tf.common import get_perm_from_formats
5-
from onnx_tf.common import supports_device
6-
from onnx_tf.common import exception
76
from onnx_tf.common.tf_helper import tf_shape
7+
from onnx_tf.common import sys_config
88
from .broadcast_mixin import BroadcastMixin
99
from .pad_mixin import PadMixin
1010

@@ -31,7 +31,6 @@ def conv(cls, node, input_dict, transpose=False):
3131
x_shape = tf_shape(x, tf.int32)
3232
spatial_size = x_rank - 2
3333

34-
support_cuda = supports_device("CUDA")
3534
storage_format, compute_format = get_data_format(x_rank)
3635
compute_c_idx = compute_format.find("C")
3736
spatial_format = "".join([d for d in compute_format if d not in ["N", "C"]])
@@ -94,7 +93,7 @@ def conv(cls, node, input_dict, transpose=False):
9493

9594
weight_groups = tf.split(weights, num_or_size_splits=group, axis=-1)
9695

97-
if support_cuda:
96+
if sys_config.device == 'CUDA':
9897
xs = tf.split(x, num_or_size_splits=group, axis=1)
9998
else:
10099
x = tf.transpose(x,
@@ -236,7 +235,7 @@ def conv(cls, node, input_dict, transpose=False):
236235
]
237236

238237
if len(node.inputs) == 2:
239-
if support_cuda:
238+
if sys_config.device == 'CUDA':
240239
output = tf.concat(convolved, axis=1)
241240
else:
242241
output = tf.concat(convolved, axis=-1)
@@ -247,7 +246,7 @@ def conv(cls, node, input_dict, transpose=False):
247246
bias = input_dict[node.inputs[2]]
248247
bias = cls.explicit_broadcast([x, bias], compute_c_idx)
249248

250-
if support_cuda:
249+
if sys_config.device == 'CUDA':
251250
output = tf.concat(convolved, axis=1)
252251
output = tf.add(output, bias)
253252
else:

0 commit comments

Comments
 (0)