From 246e7a61e35c88b6053d212335f0d1512799e81c Mon Sep 17 00:00:00 2001 From: garry1ng Date: Sat, 5 Oct 2019 16:59:32 +0800 Subject: [PATCH] add dilation and fix add ops in pytorch emitter --- mmdnn/conversion/pytorch/pytorch_emitter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mmdnn/conversion/pytorch/pytorch_emitter.py b/mmdnn/conversion/pytorch/pytorch_emitter.py index e4404775..6821eef2 100644 --- a/mmdnn/conversion/pytorch/pytorch_emitter.py +++ b/mmdnn/conversion/pytorch/pytorch_emitter.py @@ -155,6 +155,11 @@ def emit_Conv(self, IR_node): filter = IR_node.get_attr('kernel_shape')[-1] kernel = IR_node.get_attr('kernel_shape')[:-2] strides = IR_node.get_attr('strides')[1:-1] + dilations = IR_node.get_attr('dilations') + if dilations is None: + dilation = 1 + else: + dilation = dilations[1] if IR_node.type == 'DepthwiseConv': group = in_channels @@ -163,7 +168,7 @@ def emit_Conv(self, IR_node): else: group = IR_node.get_attr('group', 1) - self.add_init(2, "self.{} = self.__conv({}, name='{}', in_channels={}, out_channels={}, kernel_size={}, stride={}, groups={}, bias={})".format( + self.add_init(2, "self.{} = self.__conv({}, name='{}', in_channels={}, out_channels={}, kernel_size={}, stride={}, groups={}, dilation={}, bias={})".format( IR_node.variable_name, dim, IR_node.name, @@ -173,6 +178,7 @@ def emit_Conv(self, IR_node): tuple(strides), # padding, group, + dilation, IR_node.get_attr('use_bias'))) input_node = self._defuse_padding(IR_node) @@ -439,10 +445,9 @@ def emit_GRU(self, IR_node): def emit_Add(self, IR_node): - code = "{:<15} = {} + {}".format( + code = "{:<15} = {}".format( IR_node.variable_name, - self.parent_variable_name(IR_node), - self.parent_variable_name(IR_node, [1])) + ' + '.join(self.parent_variable_name(IR_node, [idx]) for idx in range(len(IR_node.in_edges)))) return code