Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/operator/leaky_relu-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace op {
namespace leakyrelu {
enum LeakyReLUOpInputs {kData, kGamma};
enum LeakyReLUOpOutputs {kOut, kMask};
enum LeakyReLUOpType {kLeakyReLU, kPReLU, kRReLU};
enum LeakyReLUOpType {kLeakyReLU, kPReLU, kRReLU, kELU};
enum LeakyReLUOpResource {kRandom};
} // namespace leakyrelu

Expand All @@ -39,9 +39,10 @@ struct LeakyReLUParam : public dmlc::Parameter<LeakyReLUParam> {
.add_enum("rrelu", leakyrelu::kRReLU)
.add_enum("leaky", leakyrelu::kLeakyReLU)
.add_enum("prelu", leakyrelu::kPReLU)
.add_enum("elu", leakyrelu::kELU)
.describe("Activation function to be applied.");
DMLC_DECLARE_FIELD(slope).set_default(0.25f)
.describe("Init slope for the activation. (For leaky only)");
.describe("Init slope for the activation. (For leaky and elu only)");
DMLC_DECLARE_FIELD(lower_bound).set_default(0.125f)
.describe("Lower bound of random slope. (For rrelu only)");
DMLC_DECLARE_FIELD(upper_bound).set_default(0.334f)
Expand Down Expand Up @@ -114,6 +115,10 @@ class LeakyReLUOp : public Operator {
}
break;
}
case leakyrelu::kELU: {
Assign(out, req[leakyrelu::kOut], F<mshadow_op::elu>(data, param_.slope));
break;
}
default:
LOG(FATAL) << "Not implmented";
}
Expand Down Expand Up @@ -179,6 +184,10 @@ class LeakyReLUOp : public Operator {
Assign(gdata, req[leakyrelu::kData], F<mshadow_op::xelu_grad>(output, mask) * grad);
break;
}
case leakyrelu::kELU: {
Assign(gdata, req[leakyrelu::kData], F<mshadow_op::elu_grad>(output, param_.slope) * grad);
break;
}
default:
LOG(FATAL) << "Not implmented";
}
Expand Down
13 changes: 13 additions & 0 deletions src/operator/mshadow_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ struct xelu_grad {
}
};

/*! \brief Exponential Linear Unit */
struct elu {
MSHADOW_XINLINE static real_t Map(real_t x, real_t a) {
return x >= 0.0f ? x : a * (expf(x) - 1.0f);
}
};

struct elu_grad {
MSHADOW_XINLINE static real_t Map(real_t x, real_t a) {
return x >= 0.0f ? 1.0f : a * expf(x);
}
};

struct tanh {
MSHADOW_XINLINE static real_t Map(real_t a) {
return tanhf( a );
Expand Down