| 49 | mType = SEMI_LINEAR; |
| 50 | } |
| 51 | virtual std::vector<Express::VARP> onGrad(Express::EXPRP expr, |
| 52 | const std::vector<Express::VARP>& backwardOutput) override { |
| 53 | std::vector<Express::VARP> result(1, nullptr); |
| 54 | auto op = expr->get(); |
| 55 | auto input = expr->inputs()[0]; |
| 56 | auto mask = _Relu(_Sign(input)); |
| 57 | if (nullptr != op->main_as_Relu() && op->main_as_Relu()->slope() != 0.0f) { |
| 58 | auto mask2 = _Cast<float>(_Less(input, _Scalar(0.0f))); |
| 59 | result[0] = (mask + mask2 * _Scalar<float>(op->main_as_Relu()->slope())) * backwardOutput[0]; |
| 60 | return result; |
| 61 | } |
| 62 | result[0] = mask * backwardOutput[0]; |
| 63 | return result; |
| 64 | } |
| 65 | }; |
| 66 | class Relu6Grad : public OpGrad { |
| 67 | public: |