Skip to content

Commit e22039f

Browse files
committed
Fix priorbox layer when multiple values given in min_size
1 parent 2ac46d5 commit e22039f

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

paddle/gserver/layers/PriorBox.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ bool PriorBoxLayer::init(const LayerMap& layerMap,
6565
std::copy(pbConf.aspect_ratio().begin(),
6666
pbConf.aspect_ratio().end(),
6767
std::back_inserter(tmp));
68-
// flip
69-
int inputRatioLength = tmp.size();
70-
for (int index = 0; index < inputRatioLength; index++) {
71-
aspectRatio_.push_back(tmp[index]);
72-
aspectRatio_.push_back(1 / tmp[index]);
68+
// flip aspect ratios
69+
for (int index = 0; index < tmp.size(); index++) {
70+
real ar = tmp[index];
71+
if (fabs(ar - 1.) < 1e-6) continue;
72+
aspectRatio_.push_back(ar);
73+
aspectRatio_.push_back(1. / ar);
7374
}
74-
numPriors_ = aspectRatio_.size();
75-
if (maxSize_.size() > 0) numPriors_++;
75+
numPriors_ = aspectRatio_.size() * minSize_.size();
76+
if (maxSize_.size() > 0) numPriors_ += maxSize_.size() * minSize_.size();
7677
return true;
7778
}
7879

@@ -99,13 +100,12 @@ void PriorBoxLayer::forward(PassType passType) {
99100
for (int w = 0; w < layerWidth; ++w) {
100101
real centerX = (w + 0.5) * stepW;
101102
real centerY = (h + 0.5) * stepH;
102-
real minSize = 0;
103103
for (size_t s = 0; s < minSize_.size(); s++) {
104-
// first prior.
105-
minSize = minSize_[s];
104+
// square prior with size minSize
105+
real minSize = minSize_[s];
106106
real boxWidth = minSize;
107107
real boxHeight = minSize;
108-
// xmin, ymin, xmax, ymax.
108+
// xmin, ymin, xmax, ymax
109109
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
110110
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
111111
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
@@ -115,7 +115,7 @@ void PriorBoxLayer::forward(PassType passType) {
115115

116116
if (maxSize_.size() > 0) {
117117
CHECK_EQ(minSize_.size(), maxSize_.size());
118-
// second prior.
118+
// square prior with size sqrt(minSize * maxSize)
119119
for (size_t s = 0; s < maxSize_.size(); s++) {
120120
real maxSize = maxSize_[s];
121121
boxWidth = boxHeight = sqrt(minSize * maxSize);
@@ -127,19 +127,19 @@ void PriorBoxLayer::forward(PassType passType) {
127127
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
128128
}
129129
}
130-
}
131-
// rest of priors.
132-
for (size_t r = 0; r < aspectRatio_.size(); r++) {
133-
real ar = aspectRatio_[r];
134-
if (fabs(ar - 1.) < 1e-6) continue;
135-
real boxWidth = minSize * sqrt(ar);
136-
real boxHeight = minSize / sqrt(ar);
137-
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
138-
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
139-
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
140-
tmpPtr[idx++] = (centerY + boxHeight / 2.) / imageHeight;
141-
// set the variance.
142-
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
130+
131+
// priors with different aspect ratios
132+
for (size_t r = 0; r < aspectRatio_.size(); r++) {
133+
real ar = aspectRatio_[r];
134+
boxWidth = minSize * sqrt(ar);
135+
boxHeight = minSize / sqrt(ar);
136+
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
137+
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
138+
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
139+
tmpPtr[idx++] = (centerY + boxHeight / 2.) / imageHeight;
140+
// set the variance.
141+
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
142+
}
143143
}
144144
}
145145
}

0 commit comments

Comments
 (0)