1 /**
2 * Copyright 2020 Huawei Technologies Co., Ltd
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 <vector>
18
19 #include "mindapi/base/shared_ptr.h"
20 #include "mindapi/ir/value.h"
21 #include "mindapi/src/helper.h"
22 #include "ops/op_name.h"
23 #include "ops/primitive_c.h"
24 #include "ops/proposal.h"
25 #include "utils/log_adapter.h"
26
27 namespace mindspore {
28 namespace ops {
29 MIND_API_OPERATOR_IMPL(Proposal, BaseOperator);
set_feat_stride(const float feat_stride)30 void Proposal::set_feat_stride(const float feat_stride) {
31 (void)this->AddAttr(kFeatStride, api::MakeValue(feat_stride));
32 }
33
get_feat_stride() const34 float Proposal::get_feat_stride() const {
35 auto value_ptr = GetAttr(kFeatStride);
36 return GetValue<float>(value_ptr);
37 }
38
set_base_size(const float base_size)39 void Proposal::set_base_size(const float base_size) { (void)this->AddAttr(kBaseSize, api::MakeValue(base_size)); }
40
get_base_size() const41 float Proposal::get_base_size() const {
42 auto value_ptr = GetAttr(kBaseSize);
43 return GetValue<float>(value_ptr);
44 }
45
set_min_size(const float min_size)46 void Proposal::set_min_size(const float min_size) { (void)this->AddAttr(kMinSize, api::MakeValue(min_size)); }
47
get_min_size() const48 float Proposal::get_min_size() const {
49 auto value_ptr = GetAttr(kMinSize);
50 return GetValue<float>(value_ptr);
51 }
52
set_ratio(const std::vector<float> & ratio)53 void Proposal::set_ratio(const std::vector<float> &ratio) { (void)this->AddAttr(kRatio, api::MakeValue(ratio)); }
54
get_ratio() const55 std::vector<float> Proposal::get_ratio() const {
56 auto value_ptr = GetAttr(kRatio);
57 return GetValue<std::vector<float>>(value_ptr);
58 }
59
set_scale(const std::vector<float> & scale)60 void Proposal::set_scale(const std::vector<float> &scale) { (void)this->AddAttr(kScale, api::MakeValue(scale)); }
61
get_scale() const62 std::vector<float> Proposal::get_scale() const {
63 auto value_ptr = GetAttr(kScale);
64 return GetValue<std::vector<float>>(value_ptr);
65 }
66
set_pre_nms_topn(const int64_t pre_nms_topn)67 void Proposal::set_pre_nms_topn(const int64_t pre_nms_topn) {
68 (void)this->AddAttr(kPreNmsTopn, api::MakeValue(pre_nms_topn));
69 }
70
get_pre_nms_topn() const71 int64_t Proposal::get_pre_nms_topn() const {
72 auto value_ptr = GetAttr(kPreNmsTopn);
73 return GetValue<int64_t>(value_ptr);
74 }
75
set_post_nms_topn(const int64_t post_nms_topn)76 void Proposal::set_post_nms_topn(const int64_t post_nms_topn) {
77 (void)this->AddAttr(kPostNmsTopn, api::MakeValue(post_nms_topn));
78 }
79
get_post_nms_topn() const80 int64_t Proposal::get_post_nms_topn() const {
81 auto value_ptr = GetAttr(kPostNmsTopn);
82 return GetValue<int64_t>(value_ptr);
83 }
84
set_nms_thresh(const float nms_thresh)85 void Proposal::set_nms_thresh(const float nms_thresh) { (void)this->AddAttr(kNmsThresh, api::MakeValue(nms_thresh)); }
86
get_nms_thresh() const87 float Proposal::get_nms_thresh() const {
88 auto value_ptr = GetAttr(kNmsThresh);
89 return GetValue<float>(value_ptr);
90 }
91
Init(const float feat_stride,const float base_size,const float min_size,const std::vector<float> & ratio,const std::vector<float> & scale,const int64_t pre_nms_topn,const int64_t post_nms_topn,const float nms_thresh)92 void Proposal::Init(const float feat_stride, const float base_size, const float min_size,
93 const std::vector<float> &ratio, const std::vector<float> &scale, const int64_t pre_nms_topn,
94 const int64_t post_nms_topn, const float nms_thresh) {
95 this->set_feat_stride(feat_stride);
96 this->set_base_size(base_size);
97 this->set_min_size(min_size);
98 this->set_ratio(ratio);
99 this->set_scale(scale);
100 this->set_pre_nms_topn(pre_nms_topn);
101 this->set_post_nms_topn(post_nms_topn);
102 this->set_nms_thresh(nms_thresh);
103 }
104 REGISTER_PRIMITIVE_C(kNameProposal, Proposal);
105 } // namespace ops
106 } // namespace mindspore
107