diff --git a/paddle/gserver/tests/test_LayerGrad.cpp b/paddle/gserver/tests/test_LayerGrad.cpp index 77feb6d4c9efeaf2d4afd65e6ae351f66c034789..b6282b472fd54bc744c18b7034727e7ac349d88c 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); } }