提交 ca7c5a24 编写于 作者: Y yangyaming

Fix order of prior boxes.

上级 2924c92a
...@@ -28,7 +28,7 @@ namespace paddle { ...@@ -28,7 +28,7 @@ namespace paddle {
*/ */
class PriorBoxLayer : public Layer { class PriorBoxLayer : public Layer {
public: public: // NOLINT
explicit PriorBoxLayer(const LayerConfig& config) : Layer(config) {} explicit PriorBoxLayer(const LayerConfig& config) : Layer(config) {}
bool init(const LayerMap& layerMap, bool init(const LayerMap& layerMap,
const ParameterMap& parameterMap) override; const ParameterMap& parameterMap) override;
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
void forward(PassType passType) override; void forward(PassType passType) override;
void backward(const UpdateCallback& callback) override {} void backward(const UpdateCallback& callback) override {}
protected: protected: // NOLINT
int numPriors_; int numPriors_;
std::vector<int> minSize_; std::vector<int> minSize_;
std::vector<int> maxSize_; std::vector<int> maxSize_;
...@@ -109,11 +109,18 @@ void PriorBoxLayer::forward(PassType passType) { ...@@ -109,11 +109,18 @@ void PriorBoxLayer::forward(PassType passType) {
real boxWidth = minSize; real boxWidth = minSize;
real boxHeight = minSize; real boxHeight = minSize;
// priors with different aspect ratios // first prior: aspect_ratio == 1.0, compatible to old logic
for (size_t r = 0; r < aspectRatio_.size(); r++) { tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
real ar = aspectRatio_[r]; tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
boxWidth = minSize * sqrt(ar); tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
boxHeight = minSize / sqrt(ar); tmpPtr[idx++] = (centerY + boxHeight / 2.) / imageHeight;
// set the variance.
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
if (maxSize_.size() > 0) {
// square prior with size sqrt(minSize * maxSize)
real maxSize = maxSize_[s];
boxWidth = boxHeight = sqrt(minSize * maxSize);
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth; tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight; tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth; tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
...@@ -122,10 +129,14 @@ void PriorBoxLayer::forward(PassType passType) { ...@@ -122,10 +129,14 @@ void PriorBoxLayer::forward(PassType passType) {
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t]; for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
} }
if (maxSize_.size() > 0) { // priors with different aspect ratios
// square prior with size sqrt(minSize * maxSize) for (size_t r = 0; r < aspectRatio_.size(); r++) {
real maxSize = maxSize_[s]; real ar = aspectRatio_[r];
boxWidth = boxHeight = sqrt(minSize * maxSize); if (fabs(ar - 1.0) < 1e-6) {
continue;
}
boxWidth = minSize * sqrt(ar);
boxHeight = minSize / sqrt(ar);
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth; tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight; tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth; tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册