diff --git a/paddle/phi/kernels/cpu/nms_kernel.cc b/paddle/phi/kernels/cpu/nms_kernel.cc index 4b56f6bb9510502b4f47a5d4603626a62398d21f..6743f13fff7191f2b2245ea8b6291ab177f0e99c 100644 --- a/paddle/phi/kernels/cpu/nms_kernel.cc +++ b/paddle/phi/kernels/cpu/nms_kernel.cc @@ -69,6 +69,18 @@ void NMSKernel(const Context& dev_ctx, const DenseTensor& boxes, float threshold, DenseTensor* output) { + PADDLE_ENFORCE_EQ( + boxes.dims().size(), + 2, + phi::errors::InvalidArgument("The shape [%s] of boxes must be (N, 4).", + boxes.dims())); + + PADDLE_ENFORCE_EQ( + boxes.dims()[1], + 4, + phi::errors::InvalidArgument("The shape [%s] of boxes must be (N, 4).", + boxes.dims())); + int64_t num_boxes = boxes.dims()[0]; DenseTensor output_tmp; output_tmp.Resize(phi::make_ddim({num_boxes})); diff --git a/paddle/phi/kernels/gpu/nms_kernel.cu b/paddle/phi/kernels/gpu/nms_kernel.cu index 79b0b8dfb1825f1460d78b5d4c615d13bd965bcd..81f5ca8d1619f1d8bee4c00183ac95ffe15a43a8 100644 --- a/paddle/phi/kernels/gpu/nms_kernel.cu +++ b/paddle/phi/kernels/gpu/nms_kernel.cu @@ -59,6 +59,18 @@ void NMSKernel(const Context& dev_ctx, const DenseTensor& boxes, float threshold, DenseTensor* output) { + PADDLE_ENFORCE_EQ( + boxes.dims().size(), + 2, + phi::errors::InvalidArgument("The shape [%s] of boxes must be (N, 4).", + boxes.dims())); + + PADDLE_ENFORCE_EQ( + boxes.dims()[1], + 4, + phi::errors::InvalidArgument("The shape [%s] of boxes must be (N, 4).", + boxes.dims())); + const int64_t num_boxes = boxes.dims()[0]; const auto blocks_per_line = CeilDivide(num_boxes, threadsPerBlock); dim3 block(threadsPerBlock);