since tf.pad is enabled, the conv2d(valid) changes back to its original behavior.
Showing the changes to tools/python/convert_from_tensorflow.py (1 of 3 files). Show all
Unified · Split
| @@ -23,9 +23,6 @@ import sys, struct · 22 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | __all__ = ['convert_from_tensorflow'] |
| 25 | 25 | |
| 26 | −# as the first step to be compatible with vf_sr, it is not general. | |
| 27 | −# it will be refined step by step. | |
| 28 | − | |
| 29 | 26 | class TFConverter: |
| 30 | 27 | def __init__(self, graph_def, nodes, outfile): |
| 31 | 28 | self.graph_def = graph_def |
| @@ -36,9 +33,10 @@ class TFConverter: · 4 unmodified lines | ||
| 36 | 33 | self.name_node_dict = {} |
| 37 | 34 | self.edges = {} |
| 38 | 35 | self.conv_activations = {'Relu':0, 'Tanh':1, 'Sigmoid':2, 'LeakyRelu':4} |
| 39 | − self.conv_paddings = {'VALID':2, 'SAME':1} | |
| 36 | + self.conv_paddings = {'VALID':0, 'SAME':1} | |
| 40 | 37 | self.converted_nodes = set() |
| 41 | − self.op2code = {'Conv2D':1, 'DepthToSpace':2} | |
| 38 | + self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3} | |
| 39 | + self.mirrorpad_mode = {'CONSTANT':0, 'REFLECT':1, 'SYMMETRIC':2} | |
| 42 | 40 | |
| 43 | 41 | |
| 44 | 42 | def dump_for_tensorboard(self): |
| @@ -101,6 +99,19 @@ class TFConverter: · 56 unmodified lines | ||
| 101 | 99 | self.converted_nodes.add(node.name) |
| 102 | 100 | |
| 103 | 101 | |
| 102 | + def dump_mirrorpad_to_file(self, node, f): | |
| 103 | + assert(node.op == 'MirrorPad') | |
| 104 | + self.layer_number = self.layer_number + 1 | |
| 105 | + mode = node.attr['mode'].s | |
| 106 | + mode = self.mirrorpad_mode[mode.decode("utf-8")] | |
| 107 | + np.array([self.op2code[node.op], mode], dtype=np.uint32).tofile(f) | |
| 108 | + pnode = self.name_node_dict[node.input[1]] | |
| 109 | + self.converted_nodes.add(pnode.name) | |
| 110 | + paddings = pnode.attr['value'].tensor.tensor_content | |
| 111 | + f.write(paddings) | |
| 112 | + self.converted_nodes.add(node.name) | |
| 113 | + | |
| 114 | + | |
| 104 | 115 | def generate_layer_number(self): |
| 105 | 116 | # in current hard code implementation, the layer number is the first data written to the native model file |
| 106 | 117 | # 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: · 11 unmodified lines | ||
| 118 | 129 | self.dump_conv2d_to_file(node, f) |
| 119 | 130 | elif node.op == 'DepthToSpace': |
| 120 | 131 | self.dump_depth2space_to_file(node, f) |
| 132 | + elif node.op == 'MirrorPad': | |
| 133 | + self.dump_mirrorpad_to_file(node, f) | |
| 121 | 134 | |
| 122 | 135 | |
| 123 | 136 | def dump_to_file(self): |