This repository was archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathpriorbox.cpp
150 lines (133 loc) · 6.42 KB
/
priorbox.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "framework/operators/priorbox.h"
namespace anakin {
namespace ops {
#define INSTANCE_PRIORBOX(Ttype, Dtype, Ptype) \
template<> \
void PriorBox<Ttype, Dtype, Ptype>::operator()(OpContext<Ttype>& ctx, \
const std::vector<Tensor4dPtr<Ttype, Dtype> >& ins, \
std::vector<Tensor4dPtr<Ttype, Dtype> >& outs) { \
auto* impl = static_cast<PriorBoxHelper<Ttype, Dtype, Ptype>*>(this->_helper); \
auto& param = static_cast<PriorBoxHelper<Ttype, Dtype, Ptype>*>(this->_helper)->_param_priorbox; \
impl->_funcs_priorbox(ins, outs, param, ctx); \
}
template<typename Ttype, DataType Dtype, Precision Ptype>
Status PriorBoxHelper<Ttype, Dtype, Ptype>::InitParam() {
DLOG(WARNING) << "Parsing PriorBox op parameter.";
auto min_size_ = GET_PARAMETER(PTuple<float>, min_size);
//add new parameter
PTuple<float> fixed_size_;
if (FIND_PARAMETER(fixed_size)) {
fixed_size_ = GET_PARAMETER(PTuple<float>, fixed_size);
}
// LOG(ERROR) << "fixed_size size " << fixed_size_.size();
PTuple<float> fixed_ratio_;
if (FIND_PARAMETER(fixed_ratio)) {
fixed_ratio_ = GET_PARAMETER(PTuple<float>, fixed_ratio);;
}
//LOG(ERROR) << "fixed_ratio size " << fixed_ratio_.size();
PTuple<float> density_;
if (FIND_PARAMETER(density)) {
density_ = GET_PARAMETER(PTuple<float>, density);
}
//LOG(ERROR) << "density_ size " << density_.size();
//end
auto max_size_ = GET_PARAMETER(PTuple<float>, max_size);
auto as_ratio = GET_PARAMETER(PTuple<float>, aspect_ratio);
auto flip_flag = GET_PARAMETER(bool, is_flip);
auto clip_flag = GET_PARAMETER(bool, is_clip);
auto var = GET_PARAMETER(PTuple<float>, variance);
auto image_h = GET_PARAMETER(int, img_h);
auto image_w = GET_PARAMETER(int, img_w);
auto step_h_ = GET_PARAMETER(float, step_h);
auto step_w_ = GET_PARAMETER(float, step_w);
auto offset_ = GET_PARAMETER(float, offset);
auto order = GET_PARAMETER(PTuple<std::string>, order);
std::vector<PriorType> order_;
for (int i = 0; i < order.size(); i++) {
if (order[i] == "MIN") {
order_.push_back(PRIOR_MIN);
} else if (order[i] == "MAX") {
order_.push_back(PRIOR_MAX);
} else if (order[i] == "COM") {
order_.push_back(PRIOR_COM);
}
}
if(min_size_.size() <= 0){//min
saber::PriorBoxParam<Tensor4d<Ttype, Dtype>> param_priorbox( var.vector(), flip_flag, clip_flag, \
image_w, image_h, step_w_, step_h_, offset_, order_, \
std::vector<float>(), std::vector<float>(), std::vector<float>(), \
fixed_size_.vector(), fixed_ratio_.vector(), density_.vector());
_param_priorbox = param_priorbox;
}else{
saber::PriorBoxParam<Tensor4d<Ttype, Dtype>> param_priorbox(var.vector(), flip_flag, clip_flag, \
image_w, image_h, step_w_, step_h_, offset_, order_, \
min_size_.vector(), max_size_.vector(), as_ratio.vector(), \
std::vector<float>(), std::vector<float>(), std::vector<float>());
_param_priorbox = param_priorbox;
}
// saber::PriorBoxParam<Tensor4d<Ttype, Dtype>> param_priorbox(min_size_.vector(), max_size_.vector(), \
as_ratio.vector(), var.vector(), flip_flag, clip_flag, \
image_w, image_h, step_w_, step_h_, offset_, order_, \
fixed_size_.vector(), fixed_ratio_.vector(), density_.vector());
// _param_priorbox = param_priorbox;
return Status::OK();
}
template<typename Ttype, DataType Dtype, Precision Ptype>
Status PriorBoxHelper<Ttype, Dtype, Ptype>::Init(OpContext<Ttype>& ctx,
const std::vector<Tensor4dPtr<Ttype, Dtype> >& ins,
std::vector<Tensor4dPtr<Ttype, Dtype> >& outs) {
SABER_CHECK(_funcs_priorbox.init(ins, outs, _param_priorbox, SPECIFY, SABER_IMPL, ctx));
return Status::OK();
}
template<typename Ttype, DataType Dtype, Precision Ptype>
Status PriorBoxHelper<Ttype, Dtype, Ptype>::InferShape(const
std::vector<Tensor4dPtr<Ttype, Dtype> >& ins,
std::vector<Tensor4dPtr<Ttype, Dtype> >& outs) {
SABER_CHECK(_funcs_priorbox.compute_output_shape(ins, outs, _param_priorbox));
return Status::OK();
}
#ifdef USE_CUDA
INSTANCE_PRIORBOX(NV, AK_FLOAT, Precision::FP32);
template class PriorBoxHelper<NV, AK_FLOAT, Precision::FP32>;
ANAKIN_REGISTER_OP_HELPER(PriorBox, PriorBoxHelper, NV, AK_FLOAT, Precision::FP32);
#endif
#ifdef USE_ARM_PLACE
INSTANCE_PRIORBOX(ARM, AK_FLOAT, Precision::FP32);
template class PriorBoxHelper<ARM, AK_FLOAT, Precision::FP32>;
ANAKIN_REGISTER_OP_HELPER(PriorBox, PriorBoxHelper, ARM, AK_FLOAT, Precision::FP32);
#endif
#if defined(USE_X86_PLACE) || defined(BUILD_LITE)
INSTANCE_PRIORBOX(X86, AK_FLOAT, Precision::FP32);
template class PriorBoxHelper<X86, AK_FLOAT, Precision::FP32>;
ANAKIN_REGISTER_OP_HELPER(PriorBox, PriorBoxHelper, X86, AK_FLOAT, Precision::FP32);
#endif
//! register op
ANAKIN_REGISTER_OP(PriorBox)
.Doc("PriorBox operator")
#ifdef USE_CUDA
.__alias__<NV, AK_FLOAT, Precision::FP32>("priorbox")
#endif
#ifdef USE_ARM_PLACE
.__alias__<ARM, AK_FLOAT, Precision::FP32>("priorbox")
#endif
#if defined(USE_X86_PLACE) || defined(BUILD_LITE)
.__alias__<X86, AK_FLOAT, Precision::FP32>("priorbox")
#endif
.num_in(1)
.num_out(1)
.Args<PTuple<float>>("min_size", " min_size of bbox ")
.Args<PTuple<float>>("fixed_size", " fixed_size of bbox ")
.Args<PTuple<float>>("fixed_ratio", " fixed_ratio of bbox ")
.Args<PTuple<float>>("density_", " density_ of bbox ")
.Args<PTuple<float>>("max_size", " max_size of bbox ")
.Args<PTuple<float>>("aspect_ratio", " aspect ratio of bbox ")
.Args<bool>("is_flip", "flip flag of bbox")
.Args<bool>("is_clip", "clip flag of bbox")
.Args<PTuple<float>>("variance", " variance of bbox ")
.Args<int>("img_h", "input image height")
.Args<int>("img_w", "input image width")
.Args<float>("step_h", "height step of bbox")
.Args<float>("step_w", "width step of bbox")
.Args<float>("offset", "center offset of bbox");
} /* namespace ops */
} /* namespace anakin */