From 6bb8206d03f1a0de2646a2798c4f5220fc70a035 Mon Sep 17 00:00:00 2001 From: wangguanzhong Date: Thu, 9 Apr 2020 12:27:17 +0800 Subject: [PATCH] enhance the error message of box_clip, test=develop (#23638) --- .../fluid/operators/detection/box_clip_op.cc | 32 +++++++++++++------ .../fluid/operators/detection/box_clip_op.cu | 2 -- .../fluid/operators/detection/box_clip_op.h | 4 ++- python/paddle/fluid/layers/detection.py | 5 +++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/operators/detection/box_clip_op.cc b/paddle/fluid/operators/detection/box_clip_op.cc index 9e4c7f1619a..017ac29d7fc 100644 --- a/paddle/fluid/operators/detection/box_clip_op.cc +++ b/paddle/fluid/operators/detection/box_clip_op.cc @@ -21,22 +21,36 @@ class BoxClipOp : public framework::OperatorWithKernel { protected: void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE(ctx->HasInput("Input"), - "Input(Input) of BoxClipOp should not be null."); - PADDLE_ENFORCE(ctx->HasInput("ImInfo"), - "Input(ImInfo) of BoxClipOp should not be null."); + PADDLE_ENFORCE_EQ(ctx->HasInput("Input"), true, + platform::errors::NotFound("Input(Input) of BoxClipOp " + "is not found.")); + PADDLE_ENFORCE_EQ(ctx->HasInput("ImInfo"), true, + platform::errors::NotFound("Input(ImInfo) of BoxClipOp " + "is not found.")); auto input_box_dims = ctx->GetInputDim("Input"); auto im_info_dims = ctx->GetInputDim("ImInfo"); if (ctx->IsRuntime()) { auto input_box_size = input_box_dims.size(); - PADDLE_ENFORCE_EQ(input_box_dims[input_box_size - 1], 4, - "The last dimension of Input must be 4"); + PADDLE_ENFORCE_EQ( + input_box_dims[input_box_size - 1], 4, + platform::errors::InvalidArgument( + "The last dimension " + "of Input must be 4. But received last dimension = %d", + input_box_dims[input_box_size - 1])); PADDLE_ENFORCE_EQ(im_info_dims.size(), 2, - "The rank of Input(Input) in BoxClipOp must be 2"); - PADDLE_ENFORCE_EQ(im_info_dims[1], 3, - "The last dimension of ImInfo must be 3"); + platform::errors::InvalidArgument( + "The rank of " + "Input(Input) in BoxClipOp must be 2. But received " + "rank = %d", + im_info_dims.size())); + PADDLE_ENFORCE_EQ( + im_info_dims[1], 3, + platform::errors::InvalidArgument( + "The last dimension " + "of ImInfo must be 3. But received last dimension = %d", + im_info_dims[1])); } ctx->ShareDim("Input", /*->*/ "Output"); ctx->ShareLoD("Input", /*->*/ "Output"); diff --git a/paddle/fluid/operators/detection/box_clip_op.cu b/paddle/fluid/operators/detection/box_clip_op.cu index b727da5f7b7..e02f99a613c 100644 --- a/paddle/fluid/operators/detection/box_clip_op.cu +++ b/paddle/fluid/operators/detection/box_clip_op.cu @@ -46,8 +46,6 @@ template class GPUBoxClipKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext &context) const override { - PADDLE_ENFORCE(platform::is_gpu_place(context.GetPlace()), - "This kernel only runs on GPU device."); auto *input = context.Input("Input"); auto *im_info = context.Input("ImInfo"); auto *output = context.Output("Output"); diff --git a/paddle/fluid/operators/detection/box_clip_op.h b/paddle/fluid/operators/detection/box_clip_op.h index 74e1f88f8d8..ff6194b4715 100644 --- a/paddle/fluid/operators/detection/box_clip_op.h +++ b/paddle/fluid/operators/detection/box_clip_op.h @@ -33,7 +33,9 @@ class BoxClipKernel : public framework::OpKernel { output_box->mutable_data(context.GetPlace()); if (input_box->lod().size()) { PADDLE_ENFORCE_EQ(input_box->lod().size(), 1UL, - "Only support 1 level of LoD."); + platform::errors::InvalidArgument( + "Input(Input) of " + "BoxClip only supports 1 level of LoD.")); } auto box_lod = input_box->lod().back(); int64_t n = static_cast(box_lod.size() - 1); diff --git a/python/paddle/fluid/layers/detection.py b/python/paddle/fluid/layers/detection.py index 63bac68e747..d67642e7987 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -30,6 +30,7 @@ import math import six import numpy from functools import reduce +from ..data_feeder import convert_dtype, check_variable_and_dtype, check_type, check_dtype __all__ = [ 'prior_box', @@ -2866,6 +2867,10 @@ def box_clip(input, im_info, name=None): input=boxes, im_info=im_info) """ + check_variable_and_dtype(input, 'input', ['float32', 'float64'], 'box_clip') + check_variable_and_dtype(im_info, 'im_info', ['float32', 'float64'], + 'box_clip') + helper = LayerHelper("box_clip", **locals()) output = helper.create_variable_for_type_inference(dtype=input.dtype) inputs = {"Input": input, "ImInfo": im_info} -- GitLab