| 69 | mType = SEMI_LINEAR; |
| 70 | } |
| 71 | virtual std::vector<Express::VARP> onGrad(Express::EXPRP expr, |
| 72 | const std::vector<Express::VARP>& backwardOutput) override { |
| 73 | std::vector<Express::VARP> result{nullptr}; |
| 74 | auto op = expr->get(); |
| 75 | MNN_ASSERT(nullptr != op); |
| 76 | auto relu6 = op->main_as_Relu6(); |
| 77 | MNN_ASSERT(nullptr != relu6); |
| 78 | auto input = expr->inputs()[0]; |
| 79 | auto mask0 = _Cast<float>(_Greater(input, _Scalar(relu6->minValue()))); |
| 80 | auto mask1 = _Cast<float>(_Less(input, _Scalar(relu6->maxValue()))); |
| 81 | |
| 82 | result[0] = mask0 * mask1 * backwardOutput[0]; |
| 83 | return result; |
| 84 | } |
| 85 | }; |
| 86 | static void _create() { |
| 87 | static ReluGrad _c; |