Imported Upstream version 1.18.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / DetectionPostProcess.cc
1 /*
2  * Copyright (c) 2021 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
17 #include "GenModelTest.h"
18
19 #include <memory>
20
21 TEST_F(GenModelTest, OneOp_DetectionPostProcess_SingleBox)
22 {
23   CircleGen cgen;
24
25   int boxes = cgen.addTensor({{1, 1, 4}, circle::TensorType::TensorType_FLOAT32});
26   int scores = cgen.addTensor({{1, 1, 2}, circle::TensorType::TensorType_FLOAT32});
27   int anchors = cgen.addTensor({{1, 1, 4}, circle::TensorType::TensorType_FLOAT32});
28
29   int box_coors = cgen.addTensor({{1, 1, 4}, circle::TensorType::TensorType_FLOAT32});
30   int box_classes = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
31   int box_scores = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
32   int num_selected = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
33
34   cgen.addOperatorDetectionPostProcess(
35     {{boxes, scores, anchors}, {box_coors, box_classes, box_scores, num_selected}}, 1, 10, 10, 5, 5,
36     0.8, 0.5, 1, 1, 1);
37   cgen.setInputsAndOutputs({boxes, scores, anchors},
38                            {box_coors, box_classes, box_scores, num_selected});
39
40   _context = std::make_unique<GenModelTestContext>(cgen.finish());
41   _context->addTestCase(uniformTCD<float>({{0, 0, 0, 0}, {0, 0.9}, {0, 0, 1, 1}},
42                                           {{-0.5, -0.5, 0.5, 0.5}, {0}, {0.9}, {1}}));
43   _context->setBackends({"cpu"});
44
45   SUCCEED();
46 }
47
48 TEST_F(GenModelTest, neg_OneOp_DetectionPostProcess_SinglBox_MultiClasses)
49 {
50   CircleGen cgen;
51
52   int boxes = cgen.addTensor({{1, 1, 4}, circle::TensorType::TensorType_FLOAT32});
53   int scores = cgen.addTensor({{1, 1, 3}, circle::TensorType::TensorType_FLOAT32});
54   int anchors = cgen.addTensor({{1, 1, 4}, circle::TensorType::TensorType_FLOAT32});
55
56   int box_coors = cgen.addTensor({{1, 1, 4}, circle::TensorType::TensorType_FLOAT32});
57   int box_classes = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
58   int box_scores = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
59   int num_selected = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
60
61   cgen.addOperatorDetectionPostProcess(
62     {{boxes, scores, anchors}, {box_coors, box_classes, box_scores, num_selected}}, 2, 10, 10, 5, 5,
63     0.8, 0.5, 1, 1, 1);
64   cgen.setInputsAndOutputs({boxes, scores, anchors},
65                            {box_coors, box_classes, box_scores, num_selected});
66
67   _context = std::make_unique<GenModelTestContext>(cgen.finish());
68   _context->addTestCase(uniformTCD<float>({{0, 0, 0, 0}, {0, 0.7, 0.9}, {0, 0, 1, 1}},
69                                           {{-0.5, -0.5, 0.5, 0.5}, {1}, {0.9}, {1}}));
70   _context->setBackends({"cpu"});
71   _context->expectFailModelLoad();
72
73   SUCCEED();
74 }