diff --git a/paddle/fluid/operators/detection/box_clip_op.cc b/paddle/fluid/operators/detection/box_clip_op.cc index 017ac29d7fc6a66e8c4189011934bc40b095eb2f..73f0607fdde7fa1be9e8126a0107805acab67304 100644 --- a/paddle/fluid/operators/detection/box_clip_op.cc +++ b/paddle/fluid/operators/detection/box_clip_op.cc @@ -36,20 +36,19 @@ class BoxClipOp : public framework::OperatorWithKernel { 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", + "The last dimension of Input(Input) in BoxClipOp must be 4. " + "But received last dimension = %d", input_box_dims[input_box_size - 1])); PADDLE_ENFORCE_EQ(im_info_dims.size(), 2, platform::errors::InvalidArgument( - "The rank of " - "Input(Input) in BoxClipOp must be 2. But received " - "rank = %d", + "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", + "The last dimension of Input(ImInfo) of BoxClipOp must be 3. " + "But received last dimension = %d", im_info_dims[1])); } ctx->ShareDim("Input", /*->*/ "Output"); diff --git a/paddle/fluid/operators/detection/box_clip_op.h b/paddle/fluid/operators/detection/box_clip_op.h index ff6194b47158b049abbe864153f3c22c90dc91a8..e24cefdcd7b7258bccffd8b879f2a2b12cdfcb14 100644 --- a/paddle/fluid/operators/detection/box_clip_op.h +++ b/paddle/fluid/operators/detection/box_clip_op.h @@ -34,8 +34,10 @@ class BoxClipKernel : public framework::OpKernel { if (input_box->lod().size()) { PADDLE_ENFORCE_EQ(input_box->lod().size(), 1UL, platform::errors::InvalidArgument( - "Input(Input) of " - "BoxClip only supports 1 level of LoD.")); + "Input(Input) of BoxClip only supports 1 level " + "of LoD. But received the " + "level = %d", + input_box->lod().size())); } auto box_lod = input_box->lod().back(); int64_t n = static_cast(box_lod.size() - 1); diff --git a/paddle/fluid/operators/detection/box_coder_op.h b/paddle/fluid/operators/detection/box_coder_op.h index 61867dfcda67c4bf9e0b23fb1b6825e42aeb3a87..d120ebbeb4de5a7c83178562825d3c3cbb6c35b7 100644 --- a/paddle/fluid/operators/detection/box_coder_op.h +++ b/paddle/fluid/operators/detection/box_coder_op.h @@ -21,12 +21,18 @@ namespace operators { enum class BoxCodeType { kEncodeCenterSize = 0, kDecodeCenterSize = 1 }; inline BoxCodeType GetBoxCodeType(const std::string &type) { + PADDLE_ENFORCE_EQ( + (type == "encode_center_size") || (type == "decode_center_size"), true, + platform::errors::InvalidArgument( + "The 'code_type' attribute in BoxCoder" + " must be 'encode_center_size' or 'decode_center_size'. " + "But received 'code_type' is %s", + type)); if (type == "encode_center_size") { return BoxCodeType::kEncodeCenterSize; - } else if (type == "decode_center_size") { + } else { return BoxCodeType::kDecodeCenterSize; } - PADDLE_THROW("Not support type %s.", type); } template @@ -188,7 +194,9 @@ class BoxCoderKernel : public framework::OpKernel { PADDLE_ENFORCE_EQ(target_box->lod().size(), 1UL, platform::errors::InvalidArgument( "Input(TargetBox) of BoxCoder operator " - "supports LoD with only one level.")); + "supports LoD with only one level. But received " + "level = %d", + target_box->lod().size())); } if (prior_box_var) { PADDLE_ENFORCE_EQ(variance.empty(), true, @@ -201,7 +209,9 @@ class BoxCoderKernel : public framework::OpKernel { PADDLE_ENFORCE_EQ(static_cast(variance.size()), 4, platform::errors::InvalidArgument( "Size of attribute 'variance' of BoxCoder " - "operator should be 4")); + "operator should be 4. But received " + "size = %d", + variance.size())); } auto code_type = GetBoxCodeType(context.Attr("code_type")); bool normalized = context.Attr("box_normalized"); diff --git a/paddle/fluid/operators/roi_align_op.cc b/paddle/fluid/operators/roi_align_op.cc index 1c8d8d3a392be46689f88c5b4c44f394c03fc56b..911dfea50e2e2cf8ec8f230bfc1e0bf4836463b6 100644 --- a/paddle/fluid/operators/roi_align_op.cc +++ b/paddle/fluid/operators/roi_align_op.cc @@ -40,7 +40,7 @@ class ROIAlignOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_EQ( rois_lod_dims.size(), 1, platform::errors::InvalidArgument("The RoisLod dimension should be 1" - ", but got dim = %d", + ", but got dimension = %d", rois_lod_dims.size())); } PADDLE_ENFORCE_EQ( @@ -69,20 +69,21 @@ class ROIAlignOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_GT(pooled_height, 0, platform::errors::InvalidArgument( - "The pooled output " - "height must greater than 0. But received " - "pooled_height = %d", + "The 'pooled_height' attribute in RoIAlignOp is " + "invalid. The height must be greater than 0. But " + "received 'pooled_height' = %d", pooled_height)); PADDLE_ENFORCE_GT(pooled_width, 0, platform::errors::InvalidArgument( - "The pooled output " - "width must greater than 0. But received " - "pooled_width = %d", + "The 'pooled_width' attribute in RoIAlignOp is " + "invalid. The width must be greater than 0. But " + "received 'pooled_width' = %d", pooled_width)); PADDLE_ENFORCE_GT(spatial_scale, 0.0f, platform::errors::InvalidArgument( - "The spatial scale " - "must greater than 0 But received spatial_scale = %f", + "The 'spatial_scale' attribute in RoIAlignOp is " + "invalid. The scale must be greater than 0. But " + "received 'spatial_scale' = %f", spatial_scale)); auto out_dims = input_dims; diff --git a/paddle/fluid/operators/roi_align_op.cu b/paddle/fluid/operators/roi_align_op.cu index 2665f238d52935900873c8fde5309d700c0d34f6..4c868d22c78f60352e96485515fd63f43b5826ca 100644 --- a/paddle/fluid/operators/roi_align_op.cu +++ b/paddle/fluid/operators/roi_align_op.cu @@ -284,19 +284,26 @@ class GPUROIAlignOpKernel : public framework::OpKernel { auto lod = rois->lod(); PADDLE_ENFORCE_EQ( lod.empty(), false, - "Input(ROIs) Tensor of ROIAlignOp does not contain LoD information."); + platform::errors::InvalidArgument("Input(ROIs) in ROIAlignOp does " + "not contain LoD information.")); auto rois_lod = lod.back(); int rois_batch_size = rois_lod.size() - 1; PADDLE_ENFORCE_EQ( rois_batch_size, batch_size, platform::errors::InvalidArgument( - "The rois_batch_size and imgs " - "batch_size must be the same. But received rois_batch_size = %d, " - "batch_size = %d", + "The batch size of rois and batch size " + "of images must be the same. But received rois batch size = %d, " + "and images batch size = %d", rois_batch_size, batch_size)); int rois_num_with_lod = rois_lod[rois_batch_size]; - PADDLE_ENFORCE_EQ(rois_num, rois_num_with_lod, - "The rois_num from input and lod must be the same."); + PADDLE_ENFORCE_EQ( + rois_num, rois_num_with_lod, + platform::errors::InvalidArgument( + "The actual number of rois and the number of rois " + "provided from Input(RoIsLoD) in RoIAlign must be the same." + " But received actual number of rois is %d, and the number " + "of rois from RoIsLoD is %d", + rois_num, rois_num_with_lod)); for (int n = 0; n < rois_batch_size; ++n) { for (size_t i = rois_lod[n]; i < rois_lod[n + 1]; ++i) { roi_batch_id_data[i] = n; diff --git a/paddle/fluid/operators/roi_align_op.h b/paddle/fluid/operators/roi_align_op.h index 26ef5e396a086d545be2bec86f88048db1c86f8a..366f865411461c91b4ec88203390b15fdba4414c 100644 --- a/paddle/fluid/operators/roi_align_op.h +++ b/paddle/fluid/operators/roi_align_op.h @@ -171,9 +171,9 @@ class CPUROIAlignOpKernel : public framework::OpKernel { PADDLE_ENFORCE_EQ( rois_batch_size - 1, batch_size, platform::errors::InvalidArgument( - "The rois_batch_size and imgs " - "batch_size must be the same. But received rois_batch_size = %d, " - "batch_size = %d", + "The batch size of rois and the batch size of images " + " must be the same. But received the batch size of rois is %d, " + "and the batch size of images is %d", rois_batch_size, batch_size)); auto* rois_lod = rois_lod_t->data(); for (int n = 0; n < rois_batch_size - 1; ++n) { @@ -183,9 +183,10 @@ class CPUROIAlignOpKernel : public framework::OpKernel { } } else { auto lod = rois->lod(); - PADDLE_ENFORCE_EQ( - lod.empty(), false, - "Input(ROIs) Tensor of ROIAlignOp does not contain LoD information."); + PADDLE_ENFORCE_EQ(lod.empty(), false, + platform::errors::InvalidArgument( + "Input(ROIs) Tensor of ROIAlignOp " + "does not contain LoD information.")); auto rois_lod = lod.back(); int rois_batch_size = rois_lod.size() - 1; PADDLE_ENFORCE_EQ( @@ -196,8 +197,14 @@ class CPUROIAlignOpKernel : public framework::OpKernel { "batch_size = %d", rois_batch_size, batch_size)); int rois_num_with_lod = rois_lod[rois_batch_size]; - PADDLE_ENFORCE_EQ(rois_num, rois_num_with_lod, - "The rois_num from input and lod must be the same."); + PADDLE_ENFORCE_EQ( + rois_num, rois_num_with_lod, + platform::errors::InvalidArgument( + "The actual number of rois and the number of rois " + "provided from Input(RoIsLoD) in RoIAlign must be the same." + " But received actual number of rois is %d, and the number " + "of rois from RoIsLoD is %d", + rois_num, rois_num_with_lod)); for (int n = 0; n < rois_batch_size; ++n) { for (size_t i = rois_lod[n]; i < rois_lod[n + 1]; ++i) { roi_batch_id_data[i] = n;