From d5384e640f1f972e9685e51cf018d0ff478c4362 Mon Sep 17 00:00:00 2001 From: guosheng Date: Thu, 20 Jul 2017 13:12:10 +0800 Subject: [PATCH] refine layer gradient test of ROIPoolLayer --- paddle/gserver/tests/test_LayerGrad.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/paddle/gserver/tests/test_LayerGrad.cpp b/paddle/gserver/tests/test_LayerGrad.cpp index 77feb6d4c9e..b6282b472fd 100644 --- a/paddle/gserver/tests/test_LayerGrad.cpp +++ b/paddle/gserver/tests/test_LayerGrad.cpp @@ -1842,17 +1842,20 @@ TEST(Layer, roi_pool) { roiPoolConf->set_width(14); roiPoolConf->set_height(14); - MatrixPtr roiValue = Matrix::create(10, 10, false, false); + const size_t roiNum = 10; + const size_t roiDim = 10; + const size_t batchSize = 5; + MatrixPtr roiValue = Matrix::create(roiNum, roiDim, false, false); roiValue->zeroMem(); real* roiData = roiValue->getData(); - for (size_t i = 0; i < roiValue->getElementCnt() / 5; ++i) { - *roiData++ = std::rand() % 2; - *roiData++ = std::rand() % 224; - *roiData++ = std::rand() % 224; - size_t xMin = static_cast(*(roiData - 2)); - size_t yMin = static_cast(*(roiData - 1)); - *roiData++ = xMin + std::rand() % (224 - xMin); - *roiData++ = yMin + std::rand() % (224 - yMin); + for (size_t i = 0; i < roiNum; ++i) { + roiData[i * roiDim + 0] = std::rand() % batchSize; + roiData[i * roiDim + 1] = std::rand() % 224; // xMin + roiData[i * roiDim + 2] = std::rand() % 224; // yMin + size_t xMin = static_cast(roiData[i * roiDim + 1]); + size_t yMin = static_cast(roiData[i * roiDim + 2]); + roiData[i * roiDim + 3] = xMin + std::rand() % (224 - xMin); // xMax + roiData[i * roiDim + 4] = yMin + std::rand() % (224 - yMin); // yMax } config.inputDefs.push_back({INPUT_DATA, "input", 3 * 14 * 14, {}}); @@ -1860,7 +1863,7 @@ TEST(Layer, roi_pool) { config.layerConfig.add_inputs(); for (auto useGpu : {false, true}) { - testLayerGrad(config, "roi_pool", 5, false, useGpu, false); + testLayerGrad(config, "roi_pool", batchSize, false, useGpu, false); } } -- GitLab