提交 39d689e2 编写于 作者: G gaoyuan

Format the priorbox code

上级 0eac3992
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve. /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
...@@ -33,28 +33,28 @@ public: ...@@ -33,28 +33,28 @@ public:
}; };
bool PriorBoxLayer::init(const LayerMap& layerMap, bool PriorBoxLayer::init(const LayerMap& layerMap,
const ParameterMap& parameterMap) { const ParameterMap& parameterMap) {
Layer::init(layerMap, parameterMap); Layer::init(layerMap, parameterMap);
std::copy(config_.inputs(0).priorbox_conf().min_size().begin(), auto pb_conf = config_.inputs(0).priorbox_conf();
config_.inputs(0).priorbox_conf().min_size().end(), std::copy(pb_conf.min_size().begin(),
pb_conf.min_size().end(),
std::back_inserter(minSize_)); std::back_inserter(minSize_));
std::copy(config_.inputs(0).priorbox_conf().max_size().begin(), std::copy(pb_conf.max_size().begin(),
config_.inputs(0).priorbox_conf().max_size().end(), pb_conf.max_size().end(),
std::back_inserter(maxSize_)); std::back_inserter(maxSize_));
std::copy(config_.inputs(0).priorbox_conf().aspect_ratio().begin(), std::copy(pb_conf.aspect_ratio().begin(),
config_.inputs(0).priorbox_conf().aspect_ratio().end(), pb_conf.aspect_ratio().end(),
std::back_inserter(aspectRatio_)); std::back_inserter(aspectRatio_));
std::copy(config_.inputs(0).priorbox_conf().variance().begin(), std::copy(pb_conf.variance().begin(),
config_.inputs(0).priorbox_conf().variance().end(), pb_conf.variance().end(),
std::back_inserter(variance_)); std::back_inserter(variance_));
// flip // flip
int input_ratio_length = aspectRatio_.size(); int input_ratio_length = aspectRatio_.size();
for (int index = 0; index < input_ratio_length; index++) for (int index = 0; index < input_ratio_length; index++)
aspectRatio_.push_back(1 / aspectRatio_[index]); aspectRatio_.push_back(1 / aspectRatio_[index]);
aspectRatio_.push_back(1.); aspectRatio_.push_back(1.);
numPriors_ = aspectRatio_.size(); numPriors_ = aspectRatio_.size();
if (maxSize_.size() > 0) if (maxSize_.size() > 0) numPriors_++;
numPriors_++;
buffer_ = Matrix::create(1, 1, false, false); buffer_ = Matrix::create(1, 1, false, false);
return true; return true;
} }
...@@ -79,7 +79,7 @@ void PriorBoxLayer::forward(PassType passType) { ...@@ -79,7 +79,7 @@ void PriorBoxLayer::forward(PassType passType) {
int idx = 0; int idx = 0;
for (int h = 0; h < layer_height; ++h) { for (int h = 0; h < layer_height; ++h) {
for (int w = 0; w < layer_width; ++w) { for (int w = 0; w < layer_width; ++w) {
float center_x = (w + 0.5) * step_w; float center_x = (w + 0.5) * step_w;
float center_y = (h + 0.5) * step_h; float center_y = (h + 0.5) * step_h;
int min_size = 0; int min_size = 0;
for (size_t s = 0; s < minSize_.size(); s++) { for (size_t s = 0; s < minSize_.size(); s++) {
...@@ -109,8 +109,7 @@ void PriorBoxLayer::forward(PassType passType) { ...@@ -109,8 +109,7 @@ void PriorBoxLayer::forward(PassType passType) {
// rest of priors. // rest of priors.
for (size_t r = 0; r < aspectRatio_.size(); r++) { for (size_t r = 0; r < aspectRatio_.size(); r++) {
float ar = aspectRatio_[r]; float ar = aspectRatio_[r];
if (fabs(ar - 1.) < 1e-6) if (fabs(ar - 1.) < 1e-6) continue;
continue;
float box_width = min_size * sqrt(ar); float box_width = min_size * sqrt(ar);
float box_height = min_size / sqrt(ar); float box_height = min_size / sqrt(ar);
tmp_ptr[idx++] = (center_x - box_width / 2.) / image_width; tmp_ptr[idx++] = (center_x - box_width / 2.) / image_width;
...@@ -127,8 +126,7 @@ void PriorBoxLayer::forward(PassType passType) { ...@@ -127,8 +126,7 @@ void PriorBoxLayer::forward(PassType passType) {
for (int h = 0; h < layer_height; h++) for (int h = 0; h < layer_height; h++)
for (int w = 0; w < layer_width; w++) for (int w = 0; w < layer_width; w++)
for (int i = 0; i < numPriors_; i++) for (int i = 0; i < numPriors_; i++)
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++) tmp_ptr[idx++] = variance_[j];
tmp_ptr[idx++] = variance_[j];
MatrixPtr outV = getOutputValue(); MatrixPtr outV = getOutputValue();
outV->copyFrom(buffer_->data_, dim * 2); outV->copyFrom(buffer_->data_, dim * 2);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册