|
|
|
@ -19,19 +19,18 @@ limitations under the License. */
|
|
|
|
|
namespace paddle {
|
|
|
|
|
namespace operators {
|
|
|
|
|
|
|
|
|
|
#define REGISTER_ACTIVATION_OP_MAKER(OP_NAME, OP_COMMENT) \
|
|
|
|
|
class OP_NAME##OpMaker \
|
|
|
|
|
: public ::paddle::framework::OpProtoAndCheckerMaker { \
|
|
|
|
|
public: \
|
|
|
|
|
OP_NAME##OpMaker(OpProto *proto, OpAttrChecker *op_checker) \
|
|
|
|
|
: ::paddle::framework::OpProtoAndCheckerMaker(proto, op_checker) { \
|
|
|
|
|
AddInput("X", "Input of " #OP_NAME "operator"); \
|
|
|
|
|
AddOutput("Out", "Output of" #OP_NAME "operator"); \
|
|
|
|
|
AddAttr<bool>("use_mkldnn", \
|
|
|
|
|
"(bool, default false) Only used in mkldnn kernel") \
|
|
|
|
|
.SetDefault(false); \
|
|
|
|
|
AddComment(#OP_COMMENT); \
|
|
|
|
|
} \
|
|
|
|
|
#define REGISTER_ACTIVATION_OP_MAKER(OP_NAME, OP_COMMENT) \
|
|
|
|
|
class OP_NAME##OpMaker \
|
|
|
|
|
: public ::paddle::framework::OpProtoAndCheckerMaker { \
|
|
|
|
|
public: \
|
|
|
|
|
void Make() override { \
|
|
|
|
|
AddInput("X", "Input of " #OP_NAME "operator"); \
|
|
|
|
|
AddOutput("Out", "Output of" #OP_NAME "operator"); \
|
|
|
|
|
AddAttr<bool>("use_mkldnn", \
|
|
|
|
|
"(bool, default false) Only used in mkldnn kernel") \
|
|
|
|
|
.SetDefault(false); \
|
|
|
|
|
AddComment(#OP_COMMENT); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define REGISTER_ACTIVATION_OP_GRAD_MAKER(OP_NAME, KERNEL_TYPE) \
|
|
|
|
@ -204,8 +203,7 @@ $$out = \frac{x}{1 + |x|}$$
|
|
|
|
|
|
|
|
|
|
class LeakyReluOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
LeakyReluOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of LeakyRelu operator");
|
|
|
|
|
AddOutput("Out", "Output of LeakyRelu operator");
|
|
|
|
|
AddAttr<float>("alpha", "The small negative slope").SetDefault(0.02f);
|
|
|
|
@ -220,8 +218,7 @@ $out = \max(x, \alpha * x)$
|
|
|
|
|
|
|
|
|
|
class SoftShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
SoftShrinkOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of Softshrink operator");
|
|
|
|
|
AddOutput("Out", "Output of Softshrink operator");
|
|
|
|
|
AddAttr<float>("lambda", "non-negative offset").SetDefault(0.5f);
|
|
|
|
@ -242,8 +239,7 @@ $$
|
|
|
|
|
|
|
|
|
|
class HardShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
HardShrinkOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of HardShrink operator");
|
|
|
|
|
AddOutput("Out", "Output of HardShrink operator");
|
|
|
|
|
AddAttr<float>("threshold", "The value of threshold for HardShrink")
|
|
|
|
@ -265,8 +261,7 @@ $$
|
|
|
|
|
|
|
|
|
|
class BReluOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
BReluOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of BRelu operator");
|
|
|
|
|
AddOutput("Out", "Output of BRelu operator");
|
|
|
|
|
AddAttr<float>("t_min", "The min marginal value of BRelu")
|
|
|
|
@ -284,8 +279,7 @@ $out = \max(\min(x, t_{min}), t_{max})$
|
|
|
|
|
|
|
|
|
|
class SoftReluOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
SoftReluOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of SoftRelu operator");
|
|
|
|
|
AddOutput("Out", "Output of SoftRelu operator");
|
|
|
|
|
AddAttr<float>("threshold", "The threshold value of SoftRelu")
|
|
|
|
@ -301,8 +295,7 @@ $out = \ln(1 + \exp(\max(\min(x, threshold), threshold))$
|
|
|
|
|
|
|
|
|
|
class ELUOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
ELUOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of ELU operator");
|
|
|
|
|
AddOutput("Out", "Output of ELU operator");
|
|
|
|
|
AddAttr<float>("alpha", "The alpha value of ELU").SetDefault(1.0f);
|
|
|
|
@ -320,8 +313,7 @@ $out = \max(0, x) + \min(0, \alpha * (e^x - 1))$
|
|
|
|
|
|
|
|
|
|
class Relu6OpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
Relu6OpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of Relu6 operator");
|
|
|
|
|
AddOutput("Out", "Output of Relu6 operator");
|
|
|
|
|
AddAttr<float>("threshold", "The threshold value of Relu6")
|
|
|
|
@ -337,8 +329,7 @@ $out = \min(\max(0, x), 6)$
|
|
|
|
|
|
|
|
|
|
class PowOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
PowOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of Pow operator");
|
|
|
|
|
AddOutput("Out", "Output of Pow operator");
|
|
|
|
|
AddAttr<float>("factor", "The exponential factor of Pow").SetDefault(1.0f);
|
|
|
|
@ -353,8 +344,7 @@ $out = x^{factor}$
|
|
|
|
|
|
|
|
|
|
class STanhOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
STanhOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of STanh operator");
|
|
|
|
|
AddOutput("Out", "Output of STanh operator");
|
|
|
|
|
AddAttr<float>("scale_a", "The scale parameter of a for the input")
|
|
|
|
@ -372,8 +362,7 @@ $$out = b * \frac{e^{a * x} - e^{-a * x}}{e^{a * x} + e^{-a * x}}$$
|
|
|
|
|
|
|
|
|
|
class ThresholdedReluOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
ThresholdedReluOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of ThresholdedRelu operator");
|
|
|
|
|
AddOutput("Out", "Output of ThresholdedRelu operator");
|
|
|
|
|
AddAttr<float>("threshold", "The threshold location of activation")
|
|
|
|
@ -394,8 +383,7 @@ $$
|
|
|
|
|
|
|
|
|
|
class HardSigmoidOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
HardSigmoidOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of HardSigmoid operator");
|
|
|
|
|
AddOutput("Out", "Output of HardSigmoid operator");
|
|
|
|
|
AddAttr<float>("slope", "Slope for linear approximation of sigmoid")
|
|
|
|
@ -420,8 +408,7 @@ It is recommended to use the defaults for this activation.
|
|
|
|
|
|
|
|
|
|
class SwishOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
public:
|
|
|
|
|
SwishOpMaker(OpProto *proto, OpAttrChecker *op_checker)
|
|
|
|
|
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "Input of Swish operator");
|
|
|
|
|
AddOutput("Out", "Output of Swish operator");
|
|
|
|
|
AddAttr<float>("beta", "Constant beta of swish operator").SetDefault(1.0f);
|
|
|
|
|