diff --git a/paddle/phi/kernels/cpu/nms_kernel.cc b/paddle/phi/kernels/cpu/nms_kernel.cc index 4b56f6bb95105..6743f13fff719 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 79b0b8dfb1825..81f5ca8d1619f 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);