From 9661b21bcf7ac0e43693612db4abc8ffcad366dd Mon Sep 17 00:00:00 2001 From: namizzz <874169101@qq.com> Date: Fri, 24 Aug 2018 19:18:51 +0800 Subject: [PATCH] upsampling2d scales list --- mmdnn/conversion/cntk/cntk_emitter.py | 6 ++---- mmdnn/conversion/darknet/darknet_graph.py | 2 +- mmdnn/conversion/darknet/darknet_parser.py | 6 +++--- mmdnn/conversion/keras/keras2_parser.py | 5 +---- mmdnn/conversion/tensorflow/tensorflow_emitter.py | 6 +++--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/mmdnn/conversion/cntk/cntk_emitter.py b/mmdnn/conversion/cntk/cntk_emitter.py index 4e51cc9..d72fdd6 100644 --- a/mmdnn/conversion/cntk/cntk_emitter.py +++ b/mmdnn/conversion/cntk/cntk_emitter.py @@ -471,14 +471,12 @@ def KitModel(weight_file = None): - def emit_upsample(self, IR_node): - # print(IR_node.layer) - # assert False + def emit_UpSampling2D(self, IR_node): self.used_layers.add(IR_node.type) self.add_body(1, "{:<15} = Upsampling2D({}, stride = {}, name = '{}')".format( IR_node.variable_name, self.parent_variable_name(IR_node), - IR_node.get_attr('strides'), + IR_node.get_attr('scales')[0], IR_node.name)) diff --git a/mmdnn/conversion/darknet/darknet_graph.py b/mmdnn/conversion/darknet/darknet_graph.py index ab83084..7063118 100644 --- a/mmdnn/conversion/darknet/darknet_graph.py +++ b/mmdnn/conversion/darknet/darknet_graph.py @@ -408,7 +408,7 @@ class DarknetGraph(Graph): upsample_layer['type'] = 'upsample' upsample_param = OrderedDict() stride = block['stride'] - upsample_param['strides'] = int(stride) + upsample_param['scales'] = [int(stride), int(stride)] upsample_param['_output_shape'] = [input_shape[0]] + [q*int(stride) for q in input_shape[1:3]] + [input_shape[-1]] upsample_layer['attr'] = upsample_param self.layer_map[upsample_layer['name']] = DarknetGraphNode(upsample_layer) diff --git a/mmdnn/conversion/darknet/darknet_parser.py b/mmdnn/conversion/darknet/darknet_parser.py index 3659631..36b0896 100644 --- a/mmdnn/conversion/darknet/darknet_parser.py +++ b/mmdnn/conversion/darknet/darknet_parser.py @@ -294,10 +294,10 @@ class DarknetParser(Parser): def rename_upsample(self, source_node): - IR_node = self._convert_identity_operation(source_node, new_op='upsample') - stride = source_node.get_attr('strides') + IR_node = self._convert_identity_operation(source_node, new_op='UpSampling2D') + scales = source_node.get_attr('scales') kwargs = {} - kwargs['strides'] = stride + kwargs['scales'] = scales assign_IRnode_values(IR_node, kwargs) diff --git a/mmdnn/conversion/keras/keras2_parser.py b/mmdnn/conversion/keras/keras2_parser.py index 1e681c4..f1fe4f5 100644 --- a/mmdnn/conversion/keras/keras2_parser.py +++ b/mmdnn/conversion/keras/keras2_parser.py @@ -552,10 +552,7 @@ class Keras2Parser(Parser): self.convert_inedge(source_node, IR_node) # size - IR_node.attr["size"].list.i.extend(source_node.keras_layer.size) - - - + IR_node.attr["scales"].list.i.extend(source_node.keras_layer.size) def rename_Embedding(self, source_node): diff --git a/mmdnn/conversion/tensorflow/tensorflow_emitter.py b/mmdnn/conversion/tensorflow/tensorflow_emitter.py index 1844f62..f00b5a9 100644 --- a/mmdnn/conversion/tensorflow/tensorflow_emitter.py +++ b/mmdnn/conversion/tensorflow/tensorflow_emitter.py @@ -301,11 +301,11 @@ def KitModel(weight_file = None): def emit_UpSampling2D(self, IR_node): - size = IR_node.get_attr('size') - size = tuple(size) + scales = IR_node.get_attr('scales') + scales = tuple(scales) self.add_body(1, "{:<15} = tf.keras.layers.UpSampling2D(size={})({})".format( IR_node.variable_name, - size, + scales, self.parent_variable_name(IR_node)))