imgproc.sereg.h 5.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/**
 * \file src/opr/impl/imgproc.sereg.h
 * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
 *
 * Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

#include "megbrain/opr/imgproc.h"
#include "megbrain/serialization/sereg.h"

namespace mgb {
namespace serialization {
    //! OprMaker implementation for operators with variadic arguments
    template<>
    struct OprMaker<opr::WarpPerspective, 0> {
        using Opr = opr::WarpPerspective;
        using Param = Opr::Param;
        static cg::OperatorNodeBase* make(const Param& param,
                                          const cg::VarNodeArray& inputs,
                                          ComputingGraph& graph,
                                          const OperatorNodeConfig& config) {
            MGB_MARK_USED_VAR(graph);
            if (inputs.size() == 3) {
                return Opr::make(inputs[0], inputs[1], inputs[2], param, config)
                        .node()
                        ->owner_opr();
            } else {
                mgb_assert(inputs.size() == 4);
                return Opr::make(inputs[0], inputs[1], inputs[2], inputs[3],
                                 param, config)
                        .node()
                        ->owner_opr();
            }
        }
    };
40

M
Megvii Engine Team 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    template <>
    struct OprMaker<opr::DctChannelSelectForward, 0> {
        using Opr = opr::DctChannelSelectForward;
        using Param = Opr::Param;
        static cg::OperatorNodeBase* make(const Param& param,
                                          const cg::VarNodeArray& inputs,
                                          ComputingGraph& graph,
                                          const OperatorNodeConfig& config) {
            MGB_MARK_USED_VAR(graph);
            if (inputs.size() == 3) {
                return Opr::make(inputs[0], inputs[1], inputs[2], param, config)
                        .node()
                        ->owner_opr();
            } else {
                mgb_assert(inputs.size() == 1);
                return Opr::make(inputs[0], param, config).node()->owner_opr();
            }
        }
    };

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    template<>
    struct OprMaker<opr::WarpPerspectiveBackwardData, 0> {
        using Opr = opr::WarpPerspectiveBackwardData;
        using Param = Opr::Param;
        static cg::OperatorNodeBase* make(const Param& param,
                                          const cg::VarNodeArray& inputs,
                                          ComputingGraph& graph,
                                          const OperatorNodeConfig& config) {
            MGB_MARK_USED_VAR(graph);
            if (inputs.size() == 3) {
                return Opr::make(inputs[0], inputs[1], inputs[2], param, config)
                        .node()
                        ->owner_opr();
            } else {
                mgb_assert(inputs.size() == 4);
                return Opr::make(inputs[0], inputs[1], inputs[2], inputs[3],
                                 param, config)
                        .node()
                        ->owner_opr();
            }
        }
    };

    template<>
    struct OprMaker<opr::WarpPerspectiveBackwardMat, 0> {
        using Opr = opr::WarpPerspectiveBackwardMat;
        using Param = Opr::Param;
        static cg::OperatorNodeBase* make(const Param& param,
                                          const cg::VarNodeArray& inputs,
                                          ComputingGraph& graph,
                                          const OperatorNodeConfig& config) {
            MGB_MARK_USED_VAR(graph);
            if (inputs.size() == 3) {
                return Opr::make(inputs[0], inputs[1], inputs[2], param, config)
                        .node()
                        ->owner_opr();
            } else {
                mgb_assert(inputs.size() == 4);
                return Opr::make(inputs[0], inputs[1], inputs[2], inputs[3],
                                 param, config)
                        .node()
                        ->owner_opr();
            }
        }
    };
106 107 108 109 110
} // namespace serialization

namespace opr {

    MGB_SEREG_OPR(WarpPerspective, 0);
111 112
    MGB_SEREG_OPR(WarpPerspectiveBackwardData, 0);
    MGB_SEREG_OPR(WarpPerspectiveBackwardMat, 0);
113 114 115 116 117 118

    MGB_SEREG_OPR(Rotate, 1);
    MGB_SEREG_OPR(CvtColor, 1);
    MGB_SEREG_OPR(GaussianBlur, 1);

    MGB_SEREG_OPR(ResizeBackward, 2);
119
    MGB_SEREG_OPR(Remap, 2);
120 121
    MGB_SEREG_OPR(RemapBackwardData, 3);
    MGB_SEREG_OPR(RemapBackwardMat, 3);
122 123 124 125 126 127 128 129

    //! current warp affine version
    using WarpAffineV1 = opr::WarpAffine;
    MGB_SEREG_OPR(WarpAffineV1, 3);

    //! current resize version
    using ResizeV1 = opr::Resize;
    MGB_SEREG_OPR(ResizeV1, 2);
M
Megvii Engine Team 已提交
130 131

    MGB_SEREG_OPR(DctChannelSelect, 0);
132 133 134 135 136 137 138
} // namespace opr


} // namespace mgb


// vim: ft=cpp syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}