未验证 提交 b7ba7dc7 编写于 作者: J Jason 提交者: GitHub

Merge pull request #300 from Channingss/develop

[Paddle2onnx] add swish op
...@@ -42,7 +42,6 @@ class PaddleOpMapper(object): ...@@ -42,7 +42,6 @@ class PaddleOpMapper(object):
op_nodes = list() op_nodes = list()
input_nodes = list() input_nodes = list()
output_nodes = list() output_nodes = list()
unsupported_ops = set() unsupported_ops = set()
print("Translating PaddlePaddle to ONNX...\n") print("Translating PaddlePaddle to ONNX...\n")
...@@ -183,6 +182,41 @@ class PaddleOpMapper(object): ...@@ -183,6 +182,41 @@ class PaddleOpMapper(object):
alpha=op.attr('alpha')) alpha=op.attr('alpha'))
return node return node
def swish(self, op, block):
"""
The activation swish, y = x / (1 + exp(-beta * x))
"""
beta = op.attr('beta')
beta_name = self.get_name(op.type, 'beta')
beta_node = onnx.helper.make_node(
'Constant',
name=beta_name,
inputs=[],
outputs=[beta_name],
value=onnx.helper.make_tensor(
name=beta_name,
data_type=onnx.TensorProto.FLOAT,
dims=(),
vals=[beta]))
beta_x_name = self.get_name(op.type, 'beta_x')
beta_x_node = onnx.helper.make_node(
'Mul',
name=beta_x_name,
inputs=[op.input('X')[0], beta_name],
outputs=[beta_x_name])
sigmoid_name = self.get_name(op.type, 'sigmoid')
sigmoid_node = onnx.helper.make_node(
'Sigmoid',
name=sigmoid_name,
inputs=[beta_x_name],
outputs=[sigmoid_name])
swish_node = onnx.helper.make_node(
'Mul',
inputs=[op.input('X')[0], sigmoid_name],
outputs=op.output('Out'))
return [beta_node, beta_x_node, sigmoid_node, swish_node]
def elementwise_add(self, op, block): def elementwise_add(self, op, block):
axis = op.attr('axis') axis = op.attr('axis')
x_shape = block.var(op.input('X')[0]).shape x_shape = block.var(op.input('X')[0]).shape
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册