Not support pooling strides in channel dimension yet.
Showing the changes to tools/python (1 of 7 files). Show all
Unified · Split
| @@ -67,10 +67,12 @@ class TFConverter: · 66 unmodified lines | ||
| 67 | 67 | self.edges = {} |
| 68 | 68 | self.conv_activations = {'Relu':0, 'Tanh':1, 'Sigmoid':2, 'None':3, 'LeakyRelu':4} |
| 69 | 69 | self.conv_paddings = {'VALID':0, 'SAME':1} |
| 70 | + self.pool_paddings = {'VALID':0, 'SAME':1} | |
| 70 | 71 | self.converted_nodes = set() |
| 71 | 72 | self.conv2d_scope_names = set() |
| 72 | 73 | self.conv2d_scopename_inputname_dict = {} |
| 73 | − self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3, 'Maximum':4, 'MathBinary':5, 'MathUnary':6} | |
| 74 | + self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3, 'Maximum':4, | |
| 75 | + 'MathBinary':5, 'MathUnary':6, 'AvgPool':7} | |
| 74 | 76 | self.mathbin2code = {'Sub':0, 'Add':1, 'Mul':2, 'RealDiv':3, 'Minimum':4} |
| 75 | 77 | self.mathun2code = {'Abs':0, 'Sin':1, 'Cos':2, 'Tan':3, 'Asin':4, |
| 76 | 78 | 'Acos':5, 'Atan':6, 'Sinh':7, 'Cosh':8, 'Tanh':9, 'Asinh':10, |
| @@ -300,6 +302,37 @@ class TFConverter: · 223 unmodified lines | ||
| 300 | 302 | np.array([output_operand_index],dtype=np.uint32).tofile(f) |
| 301 | 303 | |
| 302 | 304 | |
| 305 | + def dump_avg_pool_to_file(self, node, f): | |
| 306 | + assert(node.op == 'AvgPool') | |
| 307 | + self.layer_number = self.layer_number + 1 | |
| 308 | + self.converted_nodes.add(node.name) | |
| 309 | + node0 = self.name_node_dict[node.input[0]] | |
| 310 | + strides = node.attr['strides'] | |
| 311 | + | |
| 312 | + # Tensorflow do not support pooling strides in batch dimension and | |
| 313 | + # current native NN do not support pooling strides in channel dimension, added assert() here. | |
| 314 | + assert(strides.list.i[1]==strides.list.i[2]) | |
| 315 | + assert(strides.list.i[0]==1) | |
| 316 | + assert(strides.list.i[3]==1) | |
| 317 | + strides = strides.list.i[1] | |
| 318 | + filter_node = node.attr['ksize'] | |
| 319 | + input_name = node.input[0] | |
| 320 | + | |
| 321 | + # Tensorflow do not support pooling ksize in batch dimension and channel dimension. | |
| 322 | + assert(filter_node.list.i[0]==1) | |
| 323 | + assert(filter_node.list.i[3]==1) | |
| 324 | + filter_height = filter_node.list.i[1] | |
| 325 | + filter_width = filter_node.list.i[2] | |
| 326 | + | |
| 327 | + padding = node.attr['padding'].s.decode("utf-8") | |
| 328 | + np.array([self.op2code[node.op], strides, self.pool_paddings[padding], filter_height], | |
| 329 | + dtype=np.uint32).tofile(f) | |
| 330 | + | |
| 331 | + input_operand_index = self.add_operand(input_name, Operand.IOTYPE_INPUT) | |
| 332 | + output_operand_index = self.add_operand(node.name, Operand.IOTYPE_OUTPUT) | |
| 333 | + np.array([input_operand_index, output_operand_index],dtype=np.uint32).tofile(f) | |
| 334 | + | |
| 335 | + | |
| 303 | 336 | def dump_layers_to_file(self, f): |
| 304 | 337 | for node in self.nodes: |
| 305 | 338 | if node.name in self.converted_nodes: |
| @@ -313,6 +346,8 @@ class TFConverter: · 7 unmodified lines | ||
| 313 | 346 | |
| 314 | 347 | if node.op == 'Conv2D': |
| 315 | 348 | self.dump_simple_conv2d_to_file(node, f) |
| 349 | + if node.op == 'AvgPool': | |
| 350 | + self.dump_avg_pool_to_file(node, f) | |
| 316 | 351 | elif node.op == 'DepthToSpace': |
| 317 | 352 | self.dump_depth2space_to_file(node, f) |
| 318 | 353 | elif node.op == 'MirrorPad': |