提交 f2029298 编写于 作者: G gaoyuan

Change type float to real.

上级 6f8f468f
......@@ -36,8 +36,8 @@ public:
int numPriors_;
std::vector<int> minSize_;
std::vector<int> maxSize_;
std::vector<float> aspectRatio_;
std::vector<float> variance_;
std::vector<real> aspectRatio_;
std::vector<real> variance_;
MatrixPtr buffer_;
};
......@@ -77,8 +77,8 @@ void PriorBoxLayer::forward(PassType passType) {
int imageWidth = image.getFrameWidth();
int imageHeight = image.getFrameHeight();
float stepW = static_cast<float>(imageWidth) / layerWidth;
float stepH = static_cast<float>(imageHeight) / layerHeight;
real stepW = static_cast<real>(imageWidth) / layerWidth;
real stepH = static_cast<real>(imageHeight) / layerHeight;
int dim = layerHeight * layerWidth * numPriors_ * 4;
reserveOutput(1, dim * 2);
// use a cpu buffer to compute
......@@ -88,8 +88,8 @@ void PriorBoxLayer::forward(PassType passType) {
int idx = 0;
for (int h = 0; h < layerHeight; ++h) {
for (int w = 0; w < layerWidth; ++w) {
float centerX = (w + 0.5) * stepW;
float centerY = (h + 0.5) * stepH;
real centerX = (w + 0.5) * stepW;
real centerY = (h + 0.5) * stepH;
int minSize = 0;
for (size_t s = 0; s < minSize_.size(); s++) {
// first prior.
......@@ -121,10 +121,10 @@ void PriorBoxLayer::forward(PassType passType) {
}
// rest of priors.
for (size_t r = 0; r < aspectRatio_.size(); r++) {
float ar = aspectRatio_[r];
real ar = aspectRatio_[r];
if (fabs(ar - 1.) < 1e-6) continue;
float boxWidth = minSize * sqrt(ar);
float boxHeight = minSize / sqrt(ar);
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;
......@@ -137,7 +137,7 @@ void PriorBoxLayer::forward(PassType passType) {
// clip the prior's coordidate such that it is within [0, 1]
for (int d = 0; d < dim * 2; ++d)
if ((d % 8) < 4)
tmpPtr[d] = std::min(std::max(tmpPtr[d], (float)0.), (float)1.);
tmpPtr[d] = std::min(std::max(tmpPtr[d], (real)0.), (real)1.);
MatrixPtr outV = getOutputValue();
outV->copyFrom(buffer_->data_, dim * 2);
}
......
......@@ -30,8 +30,8 @@ void doOnePriorBoxTest(size_t feature_map_width,
size_t image_height,
vector<int> min_size,
vector<int> max_size,
vector<float> aspect_ratio,
vector<float> variance,
vector<real> aspect_ratio,
vector<real> variance,
bool use_gpu,
MatrixPtr& result) {
// Setting up the priorbox layer
......@@ -71,8 +71,8 @@ void doOnePriorBoxTest(size_t feature_map_width,
TEST(Layer, priorBoxLayerFwd) {
vector<int> minSize;
vector<int> maxSize;
vector<float> aspectRatio;
vector<float> variance;
vector<real> aspectRatio;
vector<real> variance;
bool useGpu = false;
minSize.push_back(276);
......@@ -84,22 +84,22 @@ TEST(Layer, priorBoxLayerFwd) {
// CPU case 1.
MatrixPtr result;
float resultData[] = {0.04,
0.04,
0.96,
0.96,
0.1,
0.1,
0.2,
0.2,
0,
0,
1,
1,
0.1,
0.1,
0.2,
0.2};
real resultData[] = {0.04,
0.04,
0.96,
0.96,
0.1,
0.1,
0.2,
0.2,
0,
0,
1,
1,
0.1,
0.1,
0.2,
0.2};
result = Matrix::create(1, 2 * 8, false, useGpu);
result->setData(resultData);
doOnePriorBoxTest(/* feature_map_width */ 1,
......@@ -116,10 +116,10 @@ TEST(Layer, priorBoxLayerFwd) {
variance[1] = 0.2;
variance[3] = 0.1;
maxSize.pop_back();
float resultData2[] = {0, 0, 0.595, 0.595, 0.1, 0.2, 0.2, 0.1,
0.405, 0, 1, 0.595, 0.1, 0.2, 0.2, 0.1,
0, 0.405, 0.595, 1, 0.1, 0.2, 0.2, 0.1,
0.405, 0.405, 1, 1, 0.1, 0.2, 0.2, 0.1};
real resultData2[] = {0, 0, 0.595, 0.595, 0.1, 0.2, 0.2, 0.1,
0.405, 0, 1, 0.595, 0.1, 0.2, 0.2, 0.1,
0, 0.405, 0.595, 1, 0.1, 0.2, 0.2, 0.1,
0.405, 0.405, 1, 1, 0.1, 0.2, 0.2, 0.1};
Matrix::resizeOrCreate(result, 1, 4 * 8, false, useGpu);
result->setData(resultData2);
doOnePriorBoxTest(/* feature_map_width */ 2,
......@@ -134,10 +134,10 @@ TEST(Layer, priorBoxLayerFwd) {
result);
// CPU case 3.
aspectRatio.push_back(2);
float resultData3[] = {0.04, 0.04, 0.96, 0.96, 0.1, 0.2,
0.2, 0.1, 0, 0.17473088, 1, 0.825269,
0.1, 0.2, 0.2, 0.1, 0.17473088, 0,
0.825269, 1, 0.1, 0.2, 0.2, 0.1};
real resultData3[] = {0.04, 0.04, 0.96, 0.96, 0.1, 0.2,
0.2, 0.1, 0, 0.17473088, 1, 0.825269,
0.1, 0.2, 0.2, 0.1, 0.17473088, 0,
0.825269, 1, 0.1, 0.2, 0.2, 0.1};
Matrix::resizeOrCreate(result, 1, 3 * 8, false, useGpu);
result->setData(resultData3);
doOnePriorBoxTest(/* feature_map_width */ 1,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册