Browse Source

!4146 support leaky relu parser

Merge pull request !4146 from sunsuodong/leaky_relu
tags/v0.7.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
123e43cd02
4 changed files with 8 additions and 10 deletions
  1. +1
    -0
      mindspore/lite/schema/ops.fbs
  2. +1
    -0
      mindspore/lite/src/populate_parameter.cc
  3. +1
    -1
      mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h
  4. +5
    -9
      mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc

+ 1
- 0
mindspore/lite/schema/ops.fbs View File

@@ -142,6 +142,7 @@ table SoftMax {

table Activation {
type: ActivationType = 0;
alpha: float = 0.2;
}
table ActivationGrad {
type: ActivationGradType = 0;


+ 1
- 0
mindspore/lite/src/populate_parameter.cc View File

@@ -487,6 +487,7 @@ OpParameter *PopulateActivationParameter(const lite::Primitive *primitive) {
}
auto activation = primitive->Value()->value_as_Activation();
act_param->type_ = static_cast<int>(activation->type());
act_param->alpha_ = activation->alpha();
return reinterpret_cast<OpParameter *>(act_param);
}



+ 1
- 1
mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h View File

@@ -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) {


+ 5
- 9
mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc View File

@@ -25,22 +25,18 @@ STATUS CaffeReluParser::Parse(const caffe::LayerParameter &proto,
std::vector<schema::TensorT *> *weightVec) {
std::unique_ptr<schema::ActivationT> attr(new schema::ActivationT());
attr->type = schema::ActivationType_RELU;
op->primitive = std::make_unique<schema::PrimitiveT>();
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<schema::LeakyReLUT> attrLeakyReLu(new schema::LeakyReLUT());
attrLeakyReLu->negativeSlope = negative_slope;
op->primitive = std::make_unique<schema::PrimitiveT>();
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<schema::PrimitiveT>();
op->primitive->value.value = attr.release();
op->primitive->value.type = schema::PrimitiveType_Activation;
return RET_OK;
}



Loading…
Cancel
Save