| 1 | // Tencent is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | // |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | #include "pass_level1.h" |
| 16 | |
| 17 | #include "../pass_level3/fuse_expression.h" |
| 18 | |
| 19 | #include "../utils.h" |
| 20 | |
| 21 | namespace pnnx { |
| 22 | |
| 23 | class MaxUnpool2d : public FuseModulePass |
| 24 | { |
| 25 | public: |
| 26 | const char* match_type_str() const |
| 27 | { |
| 28 | return "__torch__.torch.nn.modules.pooling.MaxUnpool2d"; |
| 29 | } |
| 30 | |
| 31 | const char* type_str() const |
| 32 | { |
| 33 | return "nn.MaxUnpool2d"; |
| 34 | } |
| 35 | |
| 36 | void write(Operator* op, const std::shared_ptr<torch::jit::Graph>& graph, const torch::jit::Module& mod) const |
| 37 | { |
| 38 | graph->dump(); |
| 39 | |
| 40 | { |
| 41 | Graph pnnx_graph; |
| 42 | |
| 43 | pass_level1(mod, graph, pnnx_graph); |
| 44 | |
| 45 | fuse_expression(pnnx_graph); |
| 46 | |
| 47 | Operator* expr_op = pnnx_graph.ops[2]; |
| 48 | |
| 49 | if (expr_op->type == "pnnx.Expression") |
| 50 | { |
| 51 | std::string expr = expr_op->params["expr"].s; |
| 52 | |
| 53 | int stride0; |
| 54 | int stride1; |
| 55 | int kernel_size0; |
| 56 | int kernel_size1; |
| 57 | int padding0; |
| 58 | int padding1; |
| 59 | int nscan = sscanf(expr.c_str(), "(int(sub(add(mul(sub(size(@0,2),1),%d),%d),%d)),int(sub(add(mul(sub(size(@1,3),1),%d),%d),%d)))", &stride0, &kernel_size0, &padding0, &stride1, &kernel_size1, &padding1); |
| 60 | if (nscan == 6) |
| 61 | { |
| 62 | op->params["kernel_size"] = Parameter{kernel_size0, kernel_size1}; |
| 63 | op->params["stride"] = Parameter{stride0, stride1}; |
| 64 | op->params["padding"] = Parameter{padding0 / 2, padding1 / 2}; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | const torch::jit::Node* max_unpool2d = find_node_by_kind(graph, "aten::max_unpool2d"); |
| 70 | |
| 71 | for (auto aa : max_unpool2d->schema().arguments()) |
| 72 | { |
| 73 | fprintf(stderr, "arg %s\n", aa.name().c_str()); |
| 74 | } |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | REGISTER_GLOBAL_PNNX_FUSE_MODULE_PASS(MaxUnpool2d) |
| 79 | |
| 80 | } // namespace pnnx |