Skip to content

Commit 070812f

Browse files
Add warning for non-cpp protobuf (#1570)
* Add fixes for python protobuf Signed-off-by: Tom Wildenhain <[email protected]> * Add warning for non-cpp protobuf Signed-off-by: Tom Wildenhain <[email protected]>
1 parent d927ca0 commit 070812f

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

tests/test_optimizers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _make_onnx_const(np_val, output_name):
5959
name=output_name,
6060
data_type=utils.map_numpy_to_onnx_dtype(np_val.dtype),
6161
dims=np_val.shape,
62-
vals=np_val.flatten().astype(np_val.dtype),
62+
vals=np_val.flatten().astype(np_val.dtype).tolist(),
6363
),
6464
)
6565
return node
@@ -1514,7 +1514,7 @@ def test_identity_in_subgraph_non_graph_output(self):
15141514
name='iterate_num_value',
15151515
data_type=TensorProto.INT64,
15161516
dims=iter_num_value.shape,
1517-
vals=iter_num_value.flatten().astype(np.int64),
1517+
vals=iter_num_value.flatten().astype(np.int64).tolist(),
15181518
),
15191519
)
15201520

@@ -1527,7 +1527,7 @@ def test_identity_in_subgraph_non_graph_output(self):
15271527
name='cond_value',
15281528
data_type=TensorProto.BOOL,
15291529
dims=iter_num_value.shape,
1530-
vals=cond_value.flatten().astype(np.bool),
1530+
vals=cond_value.flatten().astype(np.bool).tolist(),
15311531
),
15321532
)
15331533

tf2onnx/convert.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ def main():
202202
outputs = None
203203
model_path = None
204204

205+
if not utils.is_cpp_protobuf():
206+
logger.warning("***IMPORTANT*** Installed protobuf is not cpp accelerated. Conversion will be extremely slow. "
207+
"See https://github.com/onnx/tensorflow-onnx/issues/1557")
208+
205209
if args.load_op_libraries:
206210
for op_path in args.load_op_libraries:
207211
tf.load_op_library(op_path)

tf2onnx/onnx_opset/reduction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def any_version(cls, opset, ctx, node, **kwargs):
277277
max_int64 = int(utils.get_max_value(np.int64))
278278
identity_shape = GraphBuilder(ctx).make_slice(
279279
{'data': data_shape, 'starts': [1], 'ends': [max_int64], 'axes': [0]})
280-
id_tensor = helper.make_tensor("value", ctx.get_dtype(data_inp), dims=[1], vals=[identity_value])
280+
id_tensor = helper.make_tensor("value", ctx.get_dtype(data_inp), dims=[1], vals=[identity_value.tolist()])
281281
identity = ctx.make_node("ConstantOfShape", [identity_shape], {'value': id_tensor}).output[0]
282282
id_unsq = GraphBuilder(ctx).make_unsqueeze({'data': identity, 'axes': [0]})
283283
data_with_id = ctx.make_node("Concat", [data_inp, id_unsq], attr={'axis': 0}).output[0]

tf2onnx/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
import shutil
1111
import tempfile
12+
import types
1213
import zipfile
1314
import logging
1415

@@ -230,6 +231,10 @@ def make_sure(bool_val, error_msg, *args):
230231
raise ValueError("make_sure failure: " + error_msg % args)
231232

232233

234+
def is_cpp_protobuf():
235+
return isinstance(ModelProto().ParseFromString, types.BuiltinFunctionType)
236+
237+
233238
def construct_graph_from_nodes(parent_g, nodes, outputs, shapes, dtypes):
234239
"""Construct Graph from nodes and outputs with specified shapes and dtypes."""
235240
# pylint: disable=protected-access

0 commit comments

Comments
 (0)