Skip to content

Commit f202929

Browse files
author
gaoyuan
committed
Change type float to real.
1 parent 6f8f468 commit f202929

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

paddle/gserver/layers/PriorBox.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class PriorBoxLayer : public Layer {
3636
int numPriors_;
3737
std::vector<int> minSize_;
3838
std::vector<int> maxSize_;
39-
std::vector<float> aspectRatio_;
40-
std::vector<float> variance_;
39+
std::vector<real> aspectRatio_;
40+
std::vector<real> variance_;
4141
MatrixPtr buffer_;
4242
};
4343

@@ -77,8 +77,8 @@ void PriorBoxLayer::forward(PassType passType) {
7777
int imageWidth = image.getFrameWidth();
7878
int imageHeight = image.getFrameHeight();
7979

80-
float stepW = static_cast<float>(imageWidth) / layerWidth;
81-
float stepH = static_cast<float>(imageHeight) / layerHeight;
80+
real stepW = static_cast<real>(imageWidth) / layerWidth;
81+
real stepH = static_cast<real>(imageHeight) / layerHeight;
8282
int dim = layerHeight * layerWidth * numPriors_ * 4;
8383
reserveOutput(1, dim * 2);
8484
// use a cpu buffer to compute
@@ -88,8 +88,8 @@ void PriorBoxLayer::forward(PassType passType) {
8888
int idx = 0;
8989
for (int h = 0; h < layerHeight; ++h) {
9090
for (int w = 0; w < layerWidth; ++w) {
91-
float centerX = (w + 0.5) * stepW;
92-
float centerY = (h + 0.5) * stepH;
91+
real centerX = (w + 0.5) * stepW;
92+
real centerY = (h + 0.5) * stepH;
9393
int minSize = 0;
9494
for (size_t s = 0; s < minSize_.size(); s++) {
9595
// first prior.
@@ -121,10 +121,10 @@ void PriorBoxLayer::forward(PassType passType) {
121121
}
122122
// rest of priors.
123123
for (size_t r = 0; r < aspectRatio_.size(); r++) {
124-
float ar = aspectRatio_[r];
124+
real ar = aspectRatio_[r];
125125
if (fabs(ar - 1.) < 1e-6) continue;
126-
float boxWidth = minSize * sqrt(ar);
127-
float boxHeight = minSize / sqrt(ar);
126+
real boxWidth = minSize * sqrt(ar);
127+
real boxHeight = minSize / sqrt(ar);
128128
tmpPtr[idx++] = (centerX - boxWidth / 2.) / imageWidth;
129129
tmpPtr[idx++] = (centerY - boxHeight / 2.) / imageHeight;
130130
tmpPtr[idx++] = (centerX + boxWidth / 2.) / imageWidth;
@@ -137,7 +137,7 @@ void PriorBoxLayer::forward(PassType passType) {
137137
// clip the prior's coordidate such that it is within [0, 1]
138138
for (int d = 0; d < dim * 2; ++d)
139139
if ((d % 8) < 4)
140-
tmpPtr[d] = std::min(std::max(tmpPtr[d], (float)0.), (float)1.);
140+
tmpPtr[d] = std::min(std::max(tmpPtr[d], (real)0.), (real)1.);
141141
MatrixPtr outV = getOutputValue();
142142
outV->copyFrom(buffer_->data_, dim * 2);
143143
}

paddle/gserver/tests/test_PriorBox.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void doOnePriorBoxTest(size_t feature_map_width,
3030
size_t image_height,
3131
vector<int> min_size,
3232
vector<int> max_size,
33-
vector<float> aspect_ratio,
34-
vector<float> variance,
33+
vector<real> aspect_ratio,
34+
vector<real> variance,
3535
bool use_gpu,
3636
MatrixPtr& result) {
3737
// Setting up the priorbox layer
@@ -71,8 +71,8 @@ void doOnePriorBoxTest(size_t feature_map_width,
7171
TEST(Layer, priorBoxLayerFwd) {
7272
vector<int> minSize;
7373
vector<int> maxSize;
74-
vector<float> aspectRatio;
75-
vector<float> variance;
74+
vector<real> aspectRatio;
75+
vector<real> variance;
7676
bool useGpu = false;
7777

7878
minSize.push_back(276);
@@ -84,22 +84,22 @@ TEST(Layer, priorBoxLayerFwd) {
8484

8585
// CPU case 1.
8686
MatrixPtr result;
87-
float resultData[] = {0.04,
88-
0.04,
89-
0.96,
90-
0.96,
91-
0.1,
92-
0.1,
93-
0.2,
94-
0.2,
95-
0,
96-
0,
97-
1,
98-
1,
99-
0.1,
100-
0.1,
101-
0.2,
102-
0.2};
87+
real resultData[] = {0.04,
88+
0.04,
89+
0.96,
90+
0.96,
91+
0.1,
92+
0.1,
93+
0.2,
94+
0.2,
95+
0,
96+
0,
97+
1,
98+
1,
99+
0.1,
100+
0.1,
101+
0.2,
102+
0.2};
103103
result = Matrix::create(1, 2 * 8, false, useGpu);
104104
result->setData(resultData);
105105
doOnePriorBoxTest(/* feature_map_width */ 1,
@@ -116,10 +116,10 @@ TEST(Layer, priorBoxLayerFwd) {
116116
variance[1] = 0.2;
117117
variance[3] = 0.1;
118118
maxSize.pop_back();
119-
float resultData2[] = {0, 0, 0.595, 0.595, 0.1, 0.2, 0.2, 0.1,
120-
0.405, 0, 1, 0.595, 0.1, 0.2, 0.2, 0.1,
121-
0, 0.405, 0.595, 1, 0.1, 0.2, 0.2, 0.1,
122-
0.405, 0.405, 1, 1, 0.1, 0.2, 0.2, 0.1};
119+
real resultData2[] = {0, 0, 0.595, 0.595, 0.1, 0.2, 0.2, 0.1,
120+
0.405, 0, 1, 0.595, 0.1, 0.2, 0.2, 0.1,
121+
0, 0.405, 0.595, 1, 0.1, 0.2, 0.2, 0.1,
122+
0.405, 0.405, 1, 1, 0.1, 0.2, 0.2, 0.1};
123123
Matrix::resizeOrCreate(result, 1, 4 * 8, false, useGpu);
124124
result->setData(resultData2);
125125
doOnePriorBoxTest(/* feature_map_width */ 2,
@@ -134,10 +134,10 @@ TEST(Layer, priorBoxLayerFwd) {
134134
result);
135135
// CPU case 3.
136136
aspectRatio.push_back(2);
137-
float resultData3[] = {0.04, 0.04, 0.96, 0.96, 0.1, 0.2,
138-
0.2, 0.1, 0, 0.17473088, 1, 0.825269,
139-
0.1, 0.2, 0.2, 0.1, 0.17473088, 0,
140-
0.825269, 1, 0.1, 0.2, 0.2, 0.1};
137+
real resultData3[] = {0.04, 0.04, 0.96, 0.96, 0.1, 0.2,
138+
0.2, 0.1, 0, 0.17473088, 1, 0.825269,
139+
0.1, 0.2, 0.2, 0.1, 0.17473088, 0,
140+
0.825269, 1, 0.1, 0.2, 0.2, 0.1};
141141
Matrix::resizeOrCreate(result, 1, 3 * 8, false, useGpu);
142142
result->setData(resultData3);
143143
doOnePriorBoxTest(/* feature_map_width */ 1,

0 commit comments

Comments
 (0)