Elffuss BraidHub

kikocis/ncnn public

master · 1.6 KiBRawPermalink
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 "convert_torch_cat.h"
16
17namespace pnnx {
18
19namespace ncnn {
20
21void convert_torch_cat(Graph& graph)
22{
23 int op_index = 0;
24
25 for (Operator* op : graph.ops)
26 {
27 if (op->type != "torch.cat")
28 continue;
29
30 op->type = "Concat";
31 op->name = std::string("cat_") + std::to_string(op_index++);
32
33 const int batch_index = op->inputs[0]->params["__batch_index"].i;
34
35 int axis = op->params.at("dim").i;
36 if (axis == batch_index)
37 {
38 fprintf(stderr, "cat along batch axis %d is not supported\n", batch_index);
39 continue;
40 }
41
42 if (axis < 0)
43 {
44 int input_rank = op->inputs[0]->shape.size();
45 axis = input_rank + axis;
46 }
47
48 if (axis > batch_index)
49 axis -= 1;
50
51 op->params["0"] = axis;
52
53 op->params.erase("dim");
54 }
55}
56
57} // namespace ncnn
58
59} // namespace pnnx