// // PoolGrad.cpp // MNN // // Created by MNN on 2019/04/22. // Copyright © 2018, Alibaba Group Holding Limited // #include "PoolGrad.hpp" #include "core/Macro.h" using namespace std; namespace MNN { using namespace MNN::Express; class PoolGrad : public OpGrad { public: PoolGrad() { mType = SEMI_LINEAR; } virtual std::vector onGrad(Express::EXPRP expr, const std::vector& backwardOutput) override { std::vector result(1, nullptr); auto outputDiff = backwardOutput[0]; std::unique_ptr forwardOp(expr->get()->UnPack()); unique_ptr newOp(new OpT); newOp->type = OpType_PoolGrad; auto copyP = new PoolT(*forwardOp->main.AsPool()); newOp->main.type = OpParameter_Pool; newOp->main.value = copyP; result[0] = Variable::create( Expr::create(std::move(newOp), {expr->inputs()[0], Variable::create(expr, 0), outputDiff})); return result; } }; static void _create() { static PoolGrad _c; OpGrad::insert(OpType_Pooling, &_c); } REGISTER_GRAD(PoolGrad_cpp, _create); };