提交 cf84d42b 编写于 作者: W Wilber 提交者: cyj1986

add min_max_aspect_ratios_order attr in prior box op test=develop (#2016)

上级 806ba6e7
...@@ -63,7 +63,8 @@ void density_prior_box(const lite::Tensor* input, ...@@ -63,7 +63,8 @@ void density_prior_box(const lite::Tensor* input,
int prior_num_, int prior_num_,
bool is_flip_, bool is_flip_,
bool is_clip_, bool is_clip_,
const std::vector<std::string>& order_) { const std::vector<std::string>& order_,
bool min_max_aspect_ratios_order) {
// compute output shape // compute output shape
int win1 = input->dims()[3]; int win1 = input->dims()[3];
int hin1 = input->dims()[2]; int hin1 = input->dims()[2];
...@@ -284,6 +285,14 @@ void density_prior_box(const lite::Tensor* input, ...@@ -284,6 +285,14 @@ void density_prior_box(const lite::Tensor* input,
//! ymax //! ymax
com_buf[com_idx++] = (center_y + box_height / 2.f) / img_height; com_buf[com_idx++] = (center_y + box_height / 2.f) / img_height;
} }
if (min_max_aspect_ratios_order) {
memcpy(_cpu_data + idx, min_buf, sizeof(float) * min_idx);
idx += min_idx;
memcpy(_cpu_data + idx, max_buf, sizeof(float) * max_idx);
idx += max_idx;
memcpy(_cpu_data + idx, com_buf, sizeof(float) * com_idx);
idx += com_idx;
} else {
memcpy(_cpu_data + idx, min_buf, sizeof(float) * min_idx); memcpy(_cpu_data + idx, min_buf, sizeof(float) * min_idx);
idx += min_idx; idx += min_idx;
memcpy(_cpu_data + idx, com_buf, sizeof(float) * com_idx); memcpy(_cpu_data + idx, com_buf, sizeof(float) * com_idx);
...@@ -291,6 +300,7 @@ void density_prior_box(const lite::Tensor* input, ...@@ -291,6 +300,7 @@ void density_prior_box(const lite::Tensor* input,
memcpy(_cpu_data + idx, max_buf, sizeof(float) * max_idx); memcpy(_cpu_data + idx, max_buf, sizeof(float) * max_idx);
idx += max_idx; idx += max_idx;
} }
}
fast_free(min_buf); fast_free(min_buf);
fast_free(max_buf); fast_free(max_buf);
fast_free(com_buf); fast_free(com_buf);
...@@ -333,7 +343,8 @@ void prior_box(const lite::Tensor* input, ...@@ -333,7 +343,8 @@ void prior_box(const lite::Tensor* input,
int prior_num, int prior_num,
bool is_flip, bool is_flip,
bool is_clip, bool is_clip,
const std::vector<std::string>& order) { const std::vector<std::string>& order,
bool min_max_aspect_ratios_order) {
density_prior_box(input, density_prior_box(input,
image, image,
boxes, boxes,
...@@ -353,7 +364,8 @@ void prior_box(const lite::Tensor* input, ...@@ -353,7 +364,8 @@ void prior_box(const lite::Tensor* input,
prior_num, prior_num,
is_flip, is_flip,
is_clip, is_clip,
order); order,
min_max_aspect_ratios_order);
} }
} // namespace math } // namespace math
......
...@@ -42,7 +42,8 @@ void density_prior_box(const lite::Tensor* input, ...@@ -42,7 +42,8 @@ void density_prior_box(const lite::Tensor* input,
int prior_num_, int prior_num_,
bool is_flip_, bool is_flip_,
bool is_clip_, bool is_clip_,
const std::vector<std::string>& order_); const std::vector<std::string>& order_,
bool min_max_aspect_ratios_order);
void prior_box(const lite::Tensor* input, void prior_box(const lite::Tensor* input,
const lite::Tensor* image, const lite::Tensor* image,
...@@ -60,7 +61,8 @@ void prior_box(const lite::Tensor* input, ...@@ -60,7 +61,8 @@ void prior_box(const lite::Tensor* input,
int prior_num, int prior_num,
bool is_flip, bool is_flip,
bool is_clip, bool is_clip,
const std::vector<std::string>& order); const std::vector<std::string>& order,
bool min_max_aspect_ratios_order);
} // namespace math } // namespace math
} // namespace arm } // namespace arm
......
...@@ -100,7 +100,8 @@ void DensityPriorBoxCompute::Run() { ...@@ -100,7 +100,8 @@ void DensityPriorBoxCompute::Run() {
prior_num, prior_num,
is_flip, is_flip,
is_clip, is_clip,
order); order,
false);
} }
} // namespace arm } // namespace arm
......
...@@ -65,6 +65,7 @@ void PriorBoxCompute::Run() { ...@@ -65,6 +65,7 @@ void PriorBoxCompute::Run() {
size_t prior_num = aspect_ratios_vec.size() * min_size.size(); size_t prior_num = aspect_ratios_vec.size() * min_size.size();
prior_num += max_size.size(); prior_num += max_size.size();
std::vector<std::string> order = param.order; std::vector<std::string> order = param.order;
bool min_max_aspect_ratios_order = param.min_max_aspect_ratios_order;
lite::arm::math::prior_box(param.input, lite::arm::math::prior_box(param.input,
param.image, param.image,
...@@ -82,7 +83,8 @@ void PriorBoxCompute::Run() { ...@@ -82,7 +83,8 @@ void PriorBoxCompute::Run() {
prior_num, prior_num,
is_flip, is_flip,
is_clip, is_clip,
order); order,
min_max_aspect_ratios_order);
} }
} // namespace arm } // namespace arm
......
...@@ -540,6 +540,7 @@ struct PriorBoxParam { ...@@ -540,6 +540,7 @@ struct PriorBoxParam {
int prior_num{0}; int prior_num{0};
// priortype: prior_min, prior_max, prior_com // priortype: prior_min, prior_max, prior_com
std::vector<std::string> order; std::vector<std::string> order;
bool min_max_aspect_ratios_order{false};
}; };
struct DensityPriorBoxParam : public PriorBoxParam { struct DensityPriorBoxParam : public PriorBoxParam {
......
...@@ -67,6 +67,10 @@ bool PriorBoxOpLite::AttachImpl(const cpp::OpDesc& opdesc, lite::Scope* scope) { ...@@ -67,6 +67,10 @@ bool PriorBoxOpLite::AttachImpl(const cpp::OpDesc& opdesc, lite::Scope* scope) {
if (opdesc.HasAttr("order")) { if (opdesc.HasAttr("order")) {
param_.order = opdesc.GetAttr<std::vector<std::string>>("order"); param_.order = opdesc.GetAttr<std::vector<std::string>>("order");
} }
if (opdesc.HasAttr("min_max_aspect_ratios_order")) {
param_.min_max_aspect_ratios_order =
opdesc.GetAttr<bool>("min_max_aspect_ratios_order");
}
return true; return true;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册