Skip to content

Commit 2ac0530

Browse files
authored
Fix opset with type long not recognized as integer in Python 2 issue (#181)
* Fix opset with type long not recognized as integer in Python 2 issue * Update frontend.py * Update frontend.py * fix another occurence
1 parent 8400226 commit 2ac0530

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

onnx_tf/frontend.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
import importlib
1010
import inspect
1111
from itertools import chain
12+
import sys
1213
import warnings
1314

1415
import numpy as np
1516
import tensorflow as tf
1617
from tensorflow.python.framework.tensor_util import MakeNdarray
1718
from tensorflow.core.framework.attr_value_pb2 import AttrValue
1819

20+
# Define long type for Python 3:
21+
if sys.version_info > (3,):
22+
long = int
23+
1924
from onnx_tf.common import (
2025
TF_TYPE_TO_ONNX_TYPE,
2126
TF_OP_STR_TO_ONNX_OP,
@@ -234,7 +239,7 @@ def tensorflow_graph_to_onnx_graph(cls,
234239
opset_dict[domain] = version
235240
defs.ONNX_DOMAIN = domain
236241
assert isinstance(
237-
version, int
242+
version, (int, long)
238243
) and (version <= defs.onnx_opset_version()) and (
239244
version >= 0
240245
), "Opset should be an int less than or equal to {}, but {}: {}".format(
@@ -412,10 +417,10 @@ def get_node_by_name(nodes, name):
412417

413418
assert isinstance(
414419
opset,
415-
(int, list,
420+
(int, long, list,
416421
tuple)), "opset is expected to int, list or tuple, but {}.".format(
417422
type(opset))
418-
if isinstance(opset, int):
423+
if isinstance(opset, (int, long)):
419424
if opset == 0:
420425
opset = defs.onnx_opset_version()
421426
opset = [("", opset)]

0 commit comments

Comments
 (0)