ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleNonMaxSuppressionV4.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
18
21
22#include <loco.h>
23#include <oops/UserExn.h>
24
25namespace luci
26{
27
29{
30 const auto &inputs = args.op.inputs;
31 const auto &outputs = args.op.outputs;
32
33 if (inputs.size() != 5)
34 return false;
35 if (outputs.size() != 2)
36 return false;
37
38 const auto tensors = args.reader.tensors();
39 const auto boxes_tensor = tensors.at(inputs[0]);
40 assert(boxes_tensor != nullptr);
41 const auto boxes_tensor_shape = wrap(boxes_tensor->shape());
42 if (boxes_tensor_shape.size() != 2)
43 return false;
44 if (boxes_tensor_shape.at(1) != 4)
45 return false;
46 assert(tensors.at(inputs[1]) != nullptr);
47 if (boxes_tensor_shape.at(0) != wrap(tensors.at(inputs[1])->shape()).at(0))
48 return false;
49
50 assert(tensors.at(inputs[2]) != nullptr);
51 if (tensors.at(inputs[2])->type() != circle::TensorType_INT32)
52 return false;
53 assert(tensors.at(inputs[3]) != nullptr);
54 if (tensors.at(inputs[3])->type() != circle::TensorType_FLOAT32)
55 return false;
56 assert(tensors.at(inputs[4]) != nullptr);
57 if (tensors.at(inputs[4])->type() != circle::TensorType_FLOAT32)
58 return false;
59
60 return true;
61}
62
70CircleNode *CircleNonMaxSuppressionV4GraphBuilder::build_node(const BuildNodeArgs &bna) const
71{
72 auto node = bna.context->graph()->nodes()->create<CircleNonMaxSuppressionV4>();
73
74 node->boxes(bna.input_nodes[0]);
75 node->scores(bna.input_nodes[1]);
76 node->max_output_size(bna.input_nodes[2]);
77 node->iou_threshold(bna.input_nodes[3]);
78 node->score_threshold(bna.input_nodes[4]);
79
80 return node;
81}
82
83CircleNode *CircleNonMaxSuppressionV4GraphBuilder::build_out(const BuildOutArgs &boa) const
84{
85 auto *nodeout = boa.node->graph()->nodes()->create<CircleNonMaxSuppressionV4Out>();
86
87 nodeout->input(boa.node);
88 nodeout->index(boa.index);
89
90 return nodeout;
91}
92
93} // namespace luci
NodeContext * nodes(void)
Definition Graph.h:218
Graph * graph(void)
Definition Node.h:70
Derived * create(Args &&...args)
Definition NodePool.h:37
bool validate(const ValidateArgs &args) const final
NON_MAX_SUPPRESSION_V4 in Circle.
VectorWrapper< T > wrap(const flatbuffers::Vector< T > *vec)