MCPcopy Create free account
hub / github.com/alibaba/MNN / onGrad

Method onGrad

tools/train/source/grad/ReluGrad.cpp:51–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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};
66class Relu6Grad : public OpGrad {
67public:

Callers

nothing calls this directly

Calls 5

_ReluFunction · 0.85
_SignFunction · 0.85
_LessFunction · 0.85
_ScalarFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected