提交 f2029298 编写于 作者: G gaoyuan

Change type float to real.

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