未验证 提交 cb17dd20 编写于 作者: W Wang Meng 提交者: GitHub

Merge pull request #7698 from will-am/fix_priorbox

Fix priorbox layer when multiple values given in min_size
...@@ -65,14 +65,19 @@ bool PriorBoxLayer::init(const LayerMap& layerMap, ...@@ -65,14 +65,19 @@ bool PriorBoxLayer::init(const LayerMap& layerMap,
std::copy(pbConf.aspect_ratio().begin(), std::copy(pbConf.aspect_ratio().begin(),
pbConf.aspect_ratio().end(), pbConf.aspect_ratio().end(),
std::back_inserter(tmp)); std::back_inserter(tmp));
// flip
int inputRatioLength = tmp.size(); if (maxSize_.size() > 0) CHECK_EQ(minSize_.size(), maxSize_.size());
for (int index = 0; index < inputRatioLength; index++) {
aspectRatio_.push_back(tmp[index]); // flip aspect ratios
aspectRatio_.push_back(1 / tmp[index]); for (int index = 0; index < tmp.size(); index++) {
real ar = tmp[index];
if (fabs(ar - 1.) < 1e-6) continue;
aspectRatio_.push_back(ar);
aspectRatio_.push_back(1. / ar);
} }
numPriors_ = aspectRatio_.size();
if (maxSize_.size() > 0) numPriors_++; numPriors_ = aspectRatio_.size() * minSize_.size() + maxSize_.size();
return true; return true;
} }
...@@ -99,50 +104,39 @@ void PriorBoxLayer::forward(PassType passType) { ...@@ -99,50 +104,39 @@ void PriorBoxLayer::forward(PassType passType) {
for (int w = 0; w < layerWidth; ++w) { for (int w = 0; w < layerWidth; ++w) {
real centerX = (w + 0.5) * stepW; real centerX = (w + 0.5) * stepW;
real centerY = (h + 0.5) * stepH; real centerY = (h + 0.5) * stepH;
real minSize = 0;
for (size_t s = 0; s < minSize_.size(); s++) { for (size_t s = 0; s < minSize_.size(); s++) {
// first prior. real minSize = minSize_[s];
minSize = minSize_[s];
real boxWidth = minSize; real boxWidth = minSize;
real boxHeight = minSize; real boxHeight = minSize;
// xmin, ymin, xmax, ymax.
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth; // priors with different aspect ratios
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight; 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);
// set the variance. boxHeight = minSize / sqrt(ar);
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t]; tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
tmpPtr[idx++] = (centerY + boxHeight / 2.) / imageHeight;
// set the variance.
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
}
if (maxSize_.size() > 0) { if (maxSize_.size() > 0) {
CHECK_EQ(minSize_.size(), maxSize_.size()); // square prior with size sqrt(minSize * maxSize)
// second prior. real maxSize = maxSize_[s];
for (size_t s = 0; s < maxSize_.size(); s++) { boxWidth = boxHeight = sqrt(minSize * maxSize);
real maxSize = maxSize_[s]; tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
boxWidth = boxHeight = sqrt(minSize * maxSize); tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
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; // set the variance.
tmpPtr[idx++] = (centerY + boxHeight / 2.) / imageHeight; for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
// set the variance.
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
}
} }
} }
// rest of priors.
for (size_t r = 0; r < aspectRatio_.size(); r++) {
real ar = aspectRatio_[r];
if (fabs(ar - 1.) < 1e-6) continue;
real boxWidth = minSize * sqrt(ar);
real boxHeight = minSize / sqrt(ar);
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
tmpPtr[idx++] = (centerY + boxHeight / 2.) / imageHeight;
// set the variance.
for (int t = 0; t < 4; t++) tmpPtr[idx++] = variance_[t];
}
} }
} }
// clip the prior's coordidate such that it is within [0, 1] // clip the prior's coordidate such that it is within [0, 1]
for (int d = 0; d < dim * 2; ++d) for (int d = 0; d < dim * 2; ++d)
if ((d % 8) < 4) if ((d % 8) < 4)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册