From 54d352715f81bc516747b78b755739eb87f93c81 Mon Sep 17 00:00:00 2001 From: wjj19950828 Date: Sun, 28 Nov 2021 16:43:29 +0800 Subject: [PATCH] support yolox model --- x2paddle/op_mapper/pytorch2paddle/aten.py | 36 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/x2paddle/op_mapper/pytorch2paddle/aten.py b/x2paddle/op_mapper/pytorch2paddle/aten.py index f31201f..7667d12 100755 --- a/x2paddle/op_mapper/pytorch2paddle/aten.py +++ b/x2paddle/op_mapper/pytorch2paddle/aten.py @@ -4748,6 +4748,38 @@ def aten_silu(mapper, graph, node): return current_inputs, current_outputs +def aten_silu_(mapper, graph, node): + """ 构造Silu激活的PaddleLayer。 + TorchScript示例: + %result.3 : Tensor = aten::silu_(%input.5) + 参数含义: + %result.3 (Tensor): 输出,Silu后的结果。 + %input.5 (Tensor): 需要Silu的Tensor。 + 注意: inplace这个参数在paddle中未实现 + """ + scope_name = mapper.normalize_scope_name(node) + op_name = name_generator("silu", mapper.nn_name2id) + output_name = mapper._get_outputs_name(node)[0] + layer_outputs = [op_name, output_name] + layer_inputs = {} + inputs_name, inputs_node = mapper._get_inputs_name(node) + # 获取当前节点输出的list + current_outputs = [output_name] + # 处理输入0,即%input.5 + mapper._check_input(graph, inputs_node[0], inputs_name[0], current_outputs, + scope_name) + layer_inputs["x"] = inputs_name[0] + # 获取当前节点输入的list + current_inputs = list(layer_inputs.values()) + + graph.add_layer( + "paddle.nn.Silu", + inputs=layer_inputs, + outputs=layer_outputs, + scope_name=scope_name) + return current_inputs, current_outputs + + def aten_sin(mapper, graph, node): """ 构造数学计算sin的PaddleLayer。 TorchScript示例: @@ -5732,9 +5764,9 @@ def aten_upsample_nearest2d(mapper, graph, node): if_layer.add_block(block) if_layer.inputs["input-0"] = inputs_name[1] if "size" in layer_attrs and layer_attrs["size"] is None: - mapper._check_input(graph, inputs_node[3], inputs_name[3], + mapper._check_input(graph, inputs_node[2], inputs_name[2], current_outputs, scope_name) - layer_inputs["scale_factor"] = inputs_name[3] + layer_inputs["scale_factor"] = inputs_name[2] layer_attrs["align_mode"] = 0 layer_attrs["mode"] = string("nearest") graph.add_layer( -- GitLab