From c9d4676bee930d8678c5c590e75c31e7a40a77be Mon Sep 17 00:00:00 2001 From: dengkaipeng Date: Tue, 19 Feb 2019 13:26:15 +0000 Subject: [PATCH] fix multi batch idx error. test=develop --- paddle/fluid/operators/detection/yolo_box_op.cu | 14 +++++++------- .../fluid/tests/unittests/test_yolo_box_op.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/operators/detection/yolo_box_op.cu b/paddle/fluid/operators/detection/yolo_box_op.cu index fbe934c7e..a4513bd2f 100644 --- a/paddle/fluid/operators/detection/yolo_box_op.cu +++ b/paddle/fluid/operators/detection/yolo_box_op.cu @@ -22,14 +22,14 @@ using Tensor = framework::Tensor; template __global__ void KeYoloBoxFw(const T* input, const int* imgsize, T* boxes, - T* scores, const float conf_thresh, - const int* anchors, const int h, const int w, + T* scores, const float conf_thresh, const int* anchors, + const int n, const int h, const int w, const int an_num, const int class_num, const int box_num, int input_size) { int tid = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; T box[4]; - for (; tid < box_num; tid += stride) { + for (; tid < n * box_num; tid += stride) { int grid_num = h * w; int i = tid / box_num; int j = (tid % box_num) / grid_num; @@ -99,12 +99,12 @@ class YoloBoxOpCUDAKernel : public framework::OpKernel { set_zero(dev_ctx, boxes, static_cast(0)); set_zero(dev_ctx, scores, static_cast(0)); - int grid_dim = (n * box_num + 4 - 1) / 4; - grid_dim = grid_dim > 2 ? 2 : grid_dim; + int grid_dim = (n * box_num + 512 - 1) / 512; + grid_dim = grid_dim > 8 ? 8 : grid_dim; - KeYoloBoxFw<<>>( + KeYoloBoxFw<<>>( input_data, imgsize_data, boxes_data, scores_data, conf_thresh, - anchors_data, h, w, an_num, class_num, n * box_num, input_size); + anchors_data, n, h, w, an_num, class_num, box_num, input_size); } }; diff --git a/python/paddle/fluid/tests/unittests/test_yolo_box_op.py b/python/paddle/fluid/tests/unittests/test_yolo_box_op.py index e28c05e3e..a1da4f64b 100644 --- a/python/paddle/fluid/tests/unittests/test_yolo_box_op.py +++ b/python/paddle/fluid/tests/unittests/test_yolo_box_op.py @@ -99,11 +99,11 @@ class TestYoloBoxOp(OpTest): def initTestCase(self): self.anchors = [10, 13, 16, 30, 33, 23] an_num = int(len(self.anchors) // 2) - self.batch_size = 1 + self.batch_size = 32 self.class_num = 2 self.conf_thresh = 0.5 self.downsample = 32 - self.x_shape = (self.batch_size, an_num * (5 + self.class_num), 2, 2) + self.x_shape = (self.batch_size, an_num * (5 + self.class_num), 13, 13) self.imgsize_shape = (self.batch_size, 2) -- GitLab