blob: a60eed4e4ed5f0ee86925df576c7034cbe856931 (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
|
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "luci/Import/Nodes/CircleNonMaxSuppressionV5.h"
#include <luci/IR/Nodes/CircleNonMaxSuppressionV5.h>
#include <luci/IR/Nodes/CircleNonMaxSuppressionV5Out.h>
#include <loco.h>
#include <oops/UserExn.h>
namespace luci
{
bool CircleNonMaxSuppressionV5GraphBuilder::validate(const ValidateArgs &args) const
{
const auto &inputs = args.op.inputs;
const auto &outputs = args.op.outputs;
if (inputs.size() != 6)
return false;
if (outputs.size() != 3)
return false;
const auto tensors = args.reader.tensors();
const auto boxes_tensor = tensors.at(inputs[0]);
assert(boxes_tensor != nullptr);
const auto boxes_tensor_shape = wrap(boxes_tensor->shape());
if (boxes_tensor_shape.size() != 2)
return false;
if (boxes_tensor_shape.at(1) != 4)
return false;
assert(tensors.at(inputs[1]) != nullptr);
if (boxes_tensor_shape.at(0) != wrap(tensors.at(inputs[1])->shape()).at(0))
return false;
assert(tensors.at(inputs[2]) != nullptr);
if (tensors.at(inputs[2])->type() != circle::TensorType_INT32)
return false;
assert(tensors.at(inputs[3]) != nullptr);
if (tensors.at(inputs[3])->type() != circle::TensorType_FLOAT32)
return false;
assert(tensors.at(inputs[4]) != nullptr);
if (tensors.at(inputs[4])->type() != circle::TensorType_FLOAT32)
return false;
assert(tensors.at(inputs[5]) != nullptr);
if (tensors.at(inputs[5])->type() != circle::TensorType_FLOAT32)
return false;
return true;
}
/**
* @brief NonMaxSuppressionV5 Node builder
*
* @note Current loco does not provide multiple outputs
* We will create multiple NonMasSuppressionV5Oout nodes to emulate this
*/
CircleNode *CircleNonMaxSuppressionV5GraphBuilder::build_node(const BuildNodeArgs &bna) const
{
auto node = bna.context->graph()->nodes()->create<CircleNonMaxSuppressionV5>();
node->boxes(bna.input_nodes[0]);
node->scores(bna.input_nodes[1]);
node->max_output_size(bna.input_nodes[2]);
node->iou_threshold(bna.input_nodes[3]);
node->score_threshold(bna.input_nodes[4]);
node->soft_nms_sigma(bna.input_nodes[5]);
return node;
}
CircleNode *CircleNonMaxSuppressionV5GraphBuilder::build_out(const BuildOutArgs &boa) const
{
auto *nodeout = boa.node->graph()->nodes()->create<CircleNonMaxSuppressionV5Out>();
nodeout->input(boa.node);
nodeout->index(boa.index);
return nodeout;
}
} // namespace luci
|