Skip to content

Commit

Permalink
Update Cast handlers for version 9
Browse files Browse the repository at this point in the history
The Cast operator was updated in ONNX opset version 9, causning
frontend and backend conversion to fail.

This PR should fix the issue:
onnx#362
  • Loading branch information
chinhuang007 committed Feb 5, 2019
1 parent ada64b9 commit 6a7588e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
14 changes: 14 additions & 0 deletions doc/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ ONNX-Tensorflow Command Line Interface

More information: `onnx-tf -h`
```
WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.
usage: onnx-tf [-h] {convert,check,optimize}
ONNX-Tensorflow Command Line Interface
Expand Down Expand Up @@ -36,6 +43,13 @@ optional arguments:

More information: `onnx-tf convert -h`
```
WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.
usage: onnx-tf [-h] --infile INFILE --outfile OUTFILE --convert_to {onnx,tf}
[--graph GRAPH] [--device DEVICE] [--strict STRICT]
[--output OUTPUT] [--opset OPSET]
Expand Down
10 changes: 5 additions & 5 deletions doc/support_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ ______
|Atan|7|
|Atanh|9|
|AveragePool|1, 7|
|BatchNormalization|1, 6, 7|
|Cast|1, 6|
|BatchNormalization|1, 6, 7, 9|
|Cast|1, 6, 9|
|Ceil|1, 6|
|Clip|1, 6|
|Compress|9|
Expand Down Expand Up @@ -160,9 +160,9 @@ ______
|Atan|7|
|Atanh|9|
|AvgPool|1, 7|
|BatchNorm|1, 6, 7|
|BatchNorm|1, 6, 7, 9|
|BiasAdd|1, 6, 7|
|Cast|1, 6|
|Cast|1, 6, 9|
|Ceil|1, 6|
|ConcatV2|1, 4|
|Conv1D|1|
Expand All @@ -177,7 +177,7 @@ ______
|Fill|1|
|Floor|1, 6|
|FloorDiv|1|
|FusedBatchNorm|1, 6, 7|
|FusedBatchNorm|1, 6, 7, 9|
|GRU|1, 3, 7|
|GatherV2|1|
|Greater|1, 7, 9|
Expand Down
7 changes: 7 additions & 0 deletions onnx_tf/handlers/backend/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ def version_1(cls, node, **kwargs):
@classmethod
def version_6(cls, node, **kwargs):
return [cls.make_tensor_from_onnx_node(node, **kwargs)]

@classmethod
def version_9(cls, node, **kwargs):
inp = kwargs["tensor_dict"][node.inputs[0]]
if (node.attrs.get("to") == tf.string):
return [tf.as_string(inp)]
return [cls.make_tensor_from_onnx_node(node, **kwargs)]
6 changes: 6 additions & 0 deletions onnx_tf/handlers/frontend/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ def version_6(cls, node, **kwargs):
dst_t = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(
tf.as_dtype(node.attr["DstT"]).as_numpy_dtype)]
return cls.make_node_from_tf_node(node, [node.inputs[0]], to=dst_t)

@classmethod
def version_9(cls, node, **kwargs):
dst_t = mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(
tf.as_dtype(node.attr["DstT"]).as_numpy_dtype)]
return cls.make_node_from_tf_node(node, [node.inputs[0]], to=dst_t)
14 changes: 7 additions & 7 deletions onnx_tf/opset_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
'Atan': [7],
'Atanh': [9],
'AveragePool': [1, 7],
'BatchNormalization': [1, 6, 7],
'Cast': [1, 6],
'BatchNormalization': [1, 6, 7, 9],
'Cast': [1, 6, 9],
'Ceil': [1, 6],
'Clip': [1, 6],
'Compress': [9],
Expand Down Expand Up @@ -151,8 +151,8 @@
'Atan': [7],
'Atanh': [9],
'AveragePool': [1, 7],
'BatchNormalization': [1, 6, 7],
'Cast': [1, 6],
'BatchNormalization': [1, 6, 7, 9],
'Cast': [1, 6, 9],
'Ceil': [1, 6],
'Clip': [],
'Compress': [],
Expand Down Expand Up @@ -286,9 +286,9 @@
'Atan': [7],
'Atanh': [9],
'AvgPool': [1, 7],
'BatchNorm': [1, 6, 7],
'BatchNorm': [1, 6, 7, 9],
'BiasAdd': [1, 6, 7],
'Cast': [1, 6],
'Cast': [1, 6, 9],
'Ceil': [1, 6],
'ConcatV2': [1, 4],
'Conv1D': [1],
Expand All @@ -303,7 +303,7 @@
'Fill': [1],
'Floor': [1, 6],
'FloorDiv': [1],
'FusedBatchNorm': [1, 6, 7],
'FusedBatchNorm': [1, 6, 7, 9],
'GRU': [1, 3, 7],
'GatherV2': [1],
'Greater': [1, 7, 9],
Expand Down
3 changes: 2 additions & 1 deletion test/backend/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def test_cast(self):
(TensorProto.DOUBLE,
tf.float64), (TensorProto.COMPLEX64,
tf.complex64), (TensorProto.COMPLEX128,
tf.complex128)]
tf.complex128),
(TensorProto.STRING, tf.string)]
for ty, tf_type in test_cases:
node_def = helper.make_node("Cast", ["input"], ["output"], to=ty)
vector = [2, 3]
Expand Down

0 comments on commit 6a7588e

Please sign in to comment.