@@ -28,15 +28,15 @@ namespace paddle {
28
28
*/
29
29
30
30
class PriorBoxLayer : public Layer {
31
- public:
31
+ public: // NOLINT
32
32
explicit PriorBoxLayer (const LayerConfig& config) : Layer(config) {}
33
33
bool init (const LayerMap& layerMap,
34
34
const ParameterMap& parameterMap) override ;
35
35
36
36
void forward (PassType passType) override ;
37
37
void backward (const UpdateCallback& callback) override {}
38
38
39
- protected:
39
+ protected: // NOLINT
40
40
int numPriors_;
41
41
std::vector<int > minSize_;
42
42
std::vector<int > maxSize_;
@@ -109,11 +109,18 @@ void PriorBoxLayer::forward(PassType passType) {
109
109
real boxWidth = minSize;
110
110
real boxHeight = minSize;
111
111
112
- // priors with different aspect ratios
113
- for (size_t r = 0 ; r < aspectRatio_.size (); r++) {
114
- real ar = aspectRatio_[r];
115
- boxWidth = minSize * sqrt (ar);
116
- boxHeight = minSize / sqrt (ar);
112
+ // first prior: aspect_ratio == 1.0, compatible to old logic
113
+ tmpPtr[idx++] = (centerX - boxWidth / 2 .) / imageWidth;
114
+ tmpPtr[idx++] = (centerY - boxHeight / 2 .) / imageHeight;
115
+ tmpPtr[idx++] = (centerX + boxWidth / 2 .) / imageWidth;
116
+ tmpPtr[idx++] = (centerY + boxHeight / 2 .) / imageHeight;
117
+ // set the variance.
118
+ for (int t = 0 ; t < 4 ; t++) tmpPtr[idx++] = variance_[t];
119
+
120
+ if (maxSize_.size () > 0 ) {
121
+ // square prior with size sqrt(minSize * maxSize)
122
+ real maxSize = maxSize_[s];
123
+ boxWidth = boxHeight = sqrt (minSize * maxSize);
117
124
tmpPtr[idx++] = (centerX - boxWidth / 2 .) / imageWidth;
118
125
tmpPtr[idx++] = (centerY - boxHeight / 2 .) / imageHeight;
119
126
tmpPtr[idx++] = (centerX + boxWidth / 2 .) / imageWidth;
@@ -122,10 +129,14 @@ void PriorBoxLayer::forward(PassType passType) {
122
129
for (int t = 0 ; t < 4 ; t++) tmpPtr[idx++] = variance_[t];
123
130
}
124
131
125
- if (maxSize_.size () > 0 ) {
126
- // square prior with size sqrt(minSize * maxSize)
127
- real maxSize = maxSize_[s];
128
- boxWidth = boxHeight = sqrt (minSize * maxSize);
132
+ // priors with different aspect ratios
133
+ for (size_t r = 0 ; r < aspectRatio_.size (); r++) {
134
+ real ar = aspectRatio_[r];
135
+ if (fabs (ar - 1.0 ) < 1e-6 ) {
136
+ continue ;
137
+ }
138
+ boxWidth = minSize * sqrt (ar);
139
+ boxHeight = minSize / sqrt (ar);
129
140
tmpPtr[idx++] = (centerX - boxWidth / 2 .) / imageWidth;
130
141
tmpPtr[idx++] = (centerY - boxHeight / 2 .) / imageHeight;
131
142
tmpPtr[idx++] = (centerX + boxWidth / 2 .) / imageWidth;
0 commit comments