diff options
author | Guo, Yejun <yejun.guo@intel.com> | 2019-07-29 09:56:54 +0800 |
---|---|---|
committer | Pedro Arthur <bygrandao@gmail.com> | 2019-07-29 12:34:19 -0300 |
commit | ccbab41039af424237eaac5c302c293ab97540f8 (patch) | |
tree | f1c93cf11a6989cb7edc9e858141f3536fa4d10e /tools/python/convert_from_tensorflow.py | |
parent | 3805aae47966b691f825abab6843f55676437a02 (diff) | |
download | ffmpeg-ccbab41039af424237eaac5c302c293ab97540f8.tar.gz |
dnn: convert tf.pad to native model in python script, and load/execute it in the c code.
since tf.pad is enabled, the conv2d(valid) changes back to its original behavior.
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
Signed-off-by: Pedro Arthur <bygrandao@gmail.com>
Diffstat (limited to 'tools/python/convert_from_tensorflow.py')
-rw-r--r-- | tools/python/convert_from_tensorflow.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/tools/python/convert_from_tensorflow.py b/tools/python/convert_from_tensorflow.py index 37049e58df..041c82cf34 100644 --- a/tools/python/convert_from_tensorflow.py +++ b/tools/python/convert_from_tensorflow.py @@ -23,9 +23,6 @@ import sys, struct __all__ = ['convert_from_tensorflow'] -# as the first step to be compatible with vf_sr, it is not general. -# it will be refined step by step. - class TFConverter: def __init__(self, graph_def, nodes, outfile): self.graph_def = graph_def @@ -36,9 +33,10 @@ class TFConverter: self.name_node_dict = {} self.edges = {} self.conv_activations = {'Relu':0, 'Tanh':1, 'Sigmoid':2, 'LeakyRelu':4} - self.conv_paddings = {'VALID':2, 'SAME':1} + self.conv_paddings = {'VALID':0, 'SAME':1} self.converted_nodes = set() - self.op2code = {'Conv2D':1, 'DepthToSpace':2} + self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3} + self.mirrorpad_mode = {'CONSTANT':0, 'REFLECT':1, 'SYMMETRIC':2} def dump_for_tensorboard(self): @@ -101,6 +99,19 @@ class TFConverter: self.converted_nodes.add(node.name) + def dump_mirrorpad_to_file(self, node, f): + assert(node.op == 'MirrorPad') + self.layer_number = self.layer_number + 1 + mode = node.attr['mode'].s + mode = self.mirrorpad_mode[mode.decode("utf-8")] + np.array([self.op2code[node.op], mode], dtype=np.uint32).tofile(f) + pnode = self.name_node_dict[node.input[1]] + self.converted_nodes.add(pnode.name) + paddings = pnode.attr['value'].tensor.tensor_content + f.write(paddings) + self.converted_nodes.add(node.name) + + def generate_layer_number(self): # in current hard code implementation, the layer number is the first data written to the native model file # it is not easy to know it at the beginning time in the general converter, so first do a dry run for compatibility @@ -118,6 +129,8 @@ class TFConverter: self.dump_conv2d_to_file(node, f) elif node.op == 'DepthToSpace': self.dump_depth2space_to_file(node, f) + elif node.op == 'MirrorPad': + self.dump_mirrorpad_to_file(node, f) def dump_to_file(self): |