|
|
@ -71,7 +71,7 @@ class TFConverter: |
|
|
|
self.conv2d_scope_names = set() |
|
|
|
self.conv2d_scope_names = set() |
|
|
|
self.conv2d_scopename_inputname_dict = {} |
|
|
|
self.conv2d_scopename_inputname_dict = {} |
|
|
|
self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3, 'Maximum':4, 'MathBinary':5} |
|
|
|
self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3, 'Maximum':4, 'MathBinary':5} |
|
|
|
self.mathbin2code = {'Sub':0} |
|
|
|
self.mathbin2code = {'Sub':0, 'Add':1} |
|
|
|
self.mirrorpad_mode = {'CONSTANT':0, 'REFLECT':1, 'SYMMETRIC':2} |
|
|
|
self.mirrorpad_mode = {'CONSTANT':0, 'REFLECT':1, 'SYMMETRIC':2} |
|
|
|
self.name_operand_dict = {} |
|
|
|
self.name_operand_dict = {} |
|
|
|
|
|
|
|
|
|
|
@ -255,8 +255,7 @@ class TFConverter: |
|
|
|
np.array([input_operand_index, output_operand_index], dtype=np.uint32).tofile(f) |
|
|
|
np.array([input_operand_index, output_operand_index], dtype=np.uint32).tofile(f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dump_sub_to_file(self, node, f): |
|
|
|
def dump_mathbinary_to_file(self, node, f): |
|
|
|
assert(node.op == 'Sub') |
|
|
|
|
|
|
|
self.layer_number = self.layer_number + 1 |
|
|
|
self.layer_number = self.layer_number + 1 |
|
|
|
self.converted_nodes.add(node.name) |
|
|
|
self.converted_nodes.add(node.name) |
|
|
|
i0_node = self.name_node_dict[node.input[0]] |
|
|
|
i0_node = self.name_node_dict[node.input[0]] |
|
|
@ -264,15 +263,13 @@ class TFConverter: |
|
|
|
np.array([self.op2code['MathBinary'], self.mathbin2code[node.op]], dtype=np.uint32).tofile(f) |
|
|
|
np.array([self.op2code['MathBinary'], self.mathbin2code[node.op]], dtype=np.uint32).tofile(f) |
|
|
|
if i0_node.op == 'Const': |
|
|
|
if i0_node.op == 'Const': |
|
|
|
scalar = i0_node.attr['value'].tensor.float_val[0] |
|
|
|
scalar = i0_node.attr['value'].tensor.float_val[0] |
|
|
|
assert(i0_node.name.find('sub/x')) |
|
|
|
np.array([1], dtype=np.uint32).tofile(f) # broadcast: 1 |
|
|
|
np.array([1], dtype=np.uint32).tofile(f) |
|
|
|
|
|
|
|
np.array([scalar], dtype=np.float32).tofile(f) |
|
|
|
np.array([scalar], dtype=np.float32).tofile(f) |
|
|
|
np.array([0], dtype=np.uint32).tofile(f) |
|
|
|
np.array([0], dtype=np.uint32).tofile(f) # broadcast: 0 |
|
|
|
input_operand_index = self.add_operand(i1_node.name, Operand.IOTYPE_INPUT) |
|
|
|
input_operand_index = self.add_operand(i1_node.name, Operand.IOTYPE_INPUT) |
|
|
|
np.array([input_operand_index], dtype=np.uint32).tofile(f) |
|
|
|
np.array([input_operand_index], dtype=np.uint32).tofile(f) |
|
|
|
elif i1_node.op == 'Const': |
|
|
|
elif i1_node.op == 'Const': |
|
|
|
scalar = i1_node.attr['value'].tensor.float_val[0] |
|
|
|
scalar = i1_node.attr['value'].tensor.float_val[0] |
|
|
|
assert(i1_node.name.find('sub/y')) |
|
|
|
|
|
|
|
np.array([0], dtype=np.uint32).tofile(f) |
|
|
|
np.array([0], dtype=np.uint32).tofile(f) |
|
|
|
input_operand_index = self.add_operand(i0_node.name, Operand.IOTYPE_INPUT) |
|
|
|
input_operand_index = self.add_operand(i0_node.name, Operand.IOTYPE_INPUT) |
|
|
|
np.array([input_operand_index], dtype=np.uint32).tofile(f) |
|
|
|
np.array([input_operand_index], dtype=np.uint32).tofile(f) |
|
|
@ -309,7 +306,9 @@ class TFConverter: |
|
|
|
elif node.op == 'Maximum': |
|
|
|
elif node.op == 'Maximum': |
|
|
|
self.dump_maximum_to_file(node, f) |
|
|
|
self.dump_maximum_to_file(node, f) |
|
|
|
elif node.op == 'Sub': |
|
|
|
elif node.op == 'Sub': |
|
|
|
self.dump_sub_to_file(node, f) |
|
|
|
self.dump_mathbinary_to_file(node, f) |
|
|
|
|
|
|
|
elif node.op == 'Add': |
|
|
|
|
|
|
|
self.dump_mathbinary_to_file(node, f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dump_operands_to_file(self, f): |
|
|
|
def dump_operands_to_file(self, f): |
|
|
|