From f2029298a7d44d396e4e87bef07c55d10a06e498 Mon Sep 17 00:00:00 2001 From: gaoyuan Date: Wed, 21 Dec 2016 10:35:43 +0800 Subject: [PATCH] Change type float to real. --- paddle/gserver/layers/PriorBox.cpp | 20 ++++----- paddle/gserver/tests/test_PriorBox.cpp | 56 +++++++++++++------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/paddle/gserver/layers/PriorBox.cpp b/paddle/gserver/layers/PriorBox.cpp index ca61dfec5f..abaeaf3c1c 100644 --- a/paddle/gserver/layers/PriorBox.cpp +++ b/paddle/gserver/layers/PriorBox.cpp @@ -36,8 +36,8 @@ public: int numPriors_; std::vector minSize_; std::vector maxSize_; - std::vector aspectRatio_; - std::vector variance_; + std::vector aspectRatio_; + std::vector variance_; MatrixPtr buffer_; }; @@ -77,8 +77,8 @@ void PriorBoxLayer::forward(PassType passType) { int imageWidth = image.getFrameWidth(); int imageHeight = image.getFrameHeight(); - float stepW = static_cast(imageWidth) / layerWidth; - float stepH = static_cast(imageHeight) / layerHeight; + real stepW = static_cast(imageWidth) / layerWidth; + real stepH = static_cast(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); } diff --git a/paddle/gserver/tests/test_PriorBox.cpp b/paddle/gserver/tests/test_PriorBox.cpp index 19dfd0f065..a6d6a24269 100644 --- a/paddle/gserver/tests/test_PriorBox.cpp +++ b/paddle/gserver/tests/test_PriorBox.cpp @@ -30,8 +30,8 @@ void doOnePriorBoxTest(size_t feature_map_width, size_t image_height, vector min_size, vector max_size, - vector aspect_ratio, - vector variance, + vector aspect_ratio, + vector 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 minSize; vector maxSize; - vector aspectRatio; - vector variance; + vector aspectRatio; + vector 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, -- GitLab