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,26 @@
import tensorflow as tf
from onnx_tf.handlers.backend_handler import BackendHandler
from onnx_tf.handlers.handler import onnx_op
@onnx_op("SequenceConstruct")
class SequenceConstruct(BackendHandler):
@classmethod
def version_11(cls, node, **kwargs):
# create an empty sequence first
tensor_dict = kwargs["tensor_dict"]
dtype = tensor_dict[node.inputs[0]].dtype
input_sequence = tf.ragged.constant([], dtype=dtype)
# insert tensors at the end of sequence
for i in range(len(node.inputs)):
input_tensor = tf.expand_dims(tensor_dict[node.inputs[i]], 0)
if input_sequence.shape[0] == 0:
output_seq = tf.RaggedTensor.from_tensor(input_tensor)
else:
output_seq = tf.concat([input_sequence, input_tensor], axis=0)
input_sequence = output_seq
return [output_seq]