From de8db1ab692e753f823e677a35ed83b30138fd3c Mon Sep 17 00:00:00 2001 From: sunsuodong Date: Sat, 8 Aug 2020 11:09:58 +0800 Subject: [PATCH] support leaky relu --- mindspore/lite/schema/ops.fbs | 1 + mindspore/lite/src/populate_parameter.cc | 1 + .../src/runtime/kernel/arm/nnacl/fp32/activation.h | 2 +- .../converter/parser/caffe/caffe_relu_parser.cc | 14 +++++--------- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mindspore/lite/schema/ops.fbs b/mindspore/lite/schema/ops.fbs index fe97b0fb9..a7fd9a5bf 100644 --- a/mindspore/lite/schema/ops.fbs +++ b/mindspore/lite/schema/ops.fbs @@ -142,6 +142,7 @@ table SoftMax { table Activation { type: ActivationType = 0; + alpha: float = 0.2; } table ActivationGrad { type: ActivationGradType = 0; diff --git a/mindspore/lite/src/populate_parameter.cc b/mindspore/lite/src/populate_parameter.cc index 22e5b42de..6a757c804 100644 --- a/mindspore/lite/src/populate_parameter.cc +++ b/mindspore/lite/src/populate_parameter.cc @@ -487,6 +487,7 @@ OpParameter *PopulateActivationParameter(const lite::Primitive *primitive) { } auto activation = primitive->Value()->value_as_Activation(); act_param->type_ = static_cast(activation->type()); + act_param->alpha_ = activation->alpha(); return reinterpret_cast(act_param); } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h index 249bfacbc..0544d3030 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h @@ -24,7 +24,7 @@ struct ActivationParameter { OpParameter op_parameter_; int type_; - float alpha_{0.01}; + float alpha_{0.2}; }; inline int Relu(const float *src, int length, float *dst) { diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc index 49ea560a5..65e571025 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc @@ -25,22 +25,18 @@ STATUS CaffeReluParser::Parse(const caffe::LayerParameter &proto, std::vector *weightVec) { std::unique_ptr attr(new schema::ActivationT()); attr->type = schema::ActivationType_RELU; - op->primitive = std::make_unique(); - op->primitive->value.value = attr.release(); - op->primitive->value.type = schema::PrimitiveType_Activation; // relu: negative_slope = 0, no parameter; // leakyrelu: negative_slope != 0; if (proto.has_relu_param() && proto.relu_param().has_negative_slope()) { float negative_slope = proto.relu_param().negative_slope(); - if (0 != negative_slope) { - std::unique_ptr attrLeakyReLu(new schema::LeakyReLUT()); - attrLeakyReLu->negativeSlope = negative_slope; - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_LeakyReLU; - op->primitive->value.value = attrLeakyReLu.release(); + attr->type = schema::ActivationType_LEAKY_RELU; + attr->alpha = negative_slope; } } + op->primitive = std::make_unique(); + op->primitive->value.value = attr.release(); + op->primitive->value.type = schema::PrimitiveType_Activation; return RET_OK; } -- GitLab