@@ -65,15 +65,19 @@ bool PriorBoxLayer::init(const LayerMap& layerMap,
65
65
std::copy (pbConf.aspect_ratio ().begin (),
66
66
pbConf.aspect_ratio ().end (),
67
67
std::back_inserter (tmp));
68
+
69
+ if (maxSize_.size () > 0 ) CHECK_EQ (minSize_.size (), maxSize_.size ());
70
+
68
71
// flip aspect ratios
69
72
for (int index = 0 ; index < tmp.size (); index++) {
70
73
real ar = tmp[index];
71
74
if (fabs (ar - 1 .) < 1e-6 ) continue ;
72
75
aspectRatio_.push_back (ar);
73
76
aspectRatio_.push_back (1 . / ar);
74
77
}
75
- numPriors_ = aspectRatio_.size () * minSize_.size ();
76
- if (maxSize_.size () > 0 ) numPriors_ += maxSize_.size () * minSize_.size ();
78
+
79
+ numPriors_ = aspectRatio_.size () * minSize_.size () + maxSize_.size ();
80
+
77
81
return true ;
78
82
}
79
83
@@ -101,32 +105,9 @@ void PriorBoxLayer::forward(PassType passType) {
101
105
real centerX = (w + 0.5 ) * stepW;
102
106
real centerY = (h + 0.5 ) * stepH;
103
107
for (size_t s = 0 ; s < minSize_.size (); s++) {
104
- // square prior with size minSize
105
108
real minSize = minSize_[s];
106
109
real boxWidth = minSize;
107
110
real boxHeight = minSize;
108
- // xmin, ymin, xmax, ymax
109
- tmpPtr[idx++] = (centerX - boxWidth / 2 .) / imageWidth;
110
- tmpPtr[idx++] = (centerY - boxHeight / 2 .) / imageHeight;
111
- tmpPtr[idx++] = (centerX + boxWidth / 2 .) / imageWidth;
112
- tmpPtr[idx++] = (centerY + boxHeight / 2 .) / imageHeight;
113
- // set the variance.
114
- for (int t = 0 ; t < 4 ; t++) tmpPtr[idx++] = variance_[t];
115
-
116
- if (maxSize_.size () > 0 ) {
117
- CHECK_EQ (minSize_.size (), maxSize_.size ());
118
- // square prior with size sqrt(minSize * maxSize)
119
- for (size_t s = 0 ; s < maxSize_.size (); s++) {
120
- real maxSize = maxSize_[s];
121
- boxWidth = boxHeight = sqrt (minSize * maxSize);
122
- tmpPtr[idx++] = (centerX - boxWidth / 2 .) / imageWidth;
123
- tmpPtr[idx++] = (centerY - boxHeight / 2 .) / imageHeight;
124
- tmpPtr[idx++] = (centerX + boxWidth / 2 .) / imageWidth;
125
- tmpPtr[idx++] = (centerY + boxHeight / 2 .) / imageHeight;
126
- // set the variance.
127
- for (int t = 0 ; t < 4 ; t++) tmpPtr[idx++] = variance_[t];
128
- }
129
- }
130
111
131
112
// priors with different aspect ratios
132
113
for (size_t r = 0 ; r < aspectRatio_.size (); r++) {
@@ -140,9 +121,22 @@ void PriorBoxLayer::forward(PassType passType) {
140
121
// set the variance.
141
122
for (int t = 0 ; t < 4 ; t++) tmpPtr[idx++] = variance_[t];
142
123
}
124
+
125
+ if (maxSize_.size () > 0 ) {
126
+ // square prior with size sqrt(minSize * maxSize)
127
+ real maxSize = maxSize_[s];
128
+ boxWidth = boxHeight = sqrt (minSize * maxSize);
129
+ tmpPtr[idx++] = (centerX - boxWidth / 2 .) / imageWidth;
130
+ tmpPtr[idx++] = (centerY - boxHeight / 2 .) / imageHeight;
131
+ tmpPtr[idx++] = (centerX + boxWidth / 2 .) / imageWidth;
132
+ tmpPtr[idx++] = (centerY + boxHeight / 2 .) / imageHeight;
133
+ // set the variance.
134
+ for (int t = 0 ; t < 4 ; t++) tmpPtr[idx++] = variance_[t];
135
+ }
143
136
}
144
137
}
145
138
}
139
+
146
140
// clip the prior's coordidate such that it is within [0, 1]
147
141
for (int d = 0 ; d < dim * 2 ; ++d)
148
142
if ((d % 8 ) < 4 )
0 commit comments