add pt2tf tool

This commit is contained in:
zxros10
2020-09-23 09:09:49 +08:00
parent 7f7b7df65d
commit 18aefa4dd0
407 changed files with 16211 additions and 0 deletions
@@ -0,0 +1,22 @@
import tensorflow as tf
from onnx_tf.handlers.backend_handler import BackendHandler
from onnx_tf.handlers.handler import onnx_op
@onnx_op("Expand")
class Expand(BackendHandler):
@classmethod
def version_8(cls, node, **kwargs):
tensor_dict = kwargs["tensor_dict"]
x, shape = tensor_dict[node.inputs[0]], tensor_dict[node.inputs[1]]
# tf.math.multiply does not support bool therefore use int8
if x.dtype is tf.bool:
ones = tf.ones(shape, dtype=tf.int8)
r = tf.cast(x, tf.int8) * ones
return [tf.cast(r, tf.bool)]
else:
ones = tf.ones(shape, dtype=x.dtype)
return [x * ones]