@@ -27,10 +27,8 @@ class CropTensorOp : public framework::OperatorWithKernel {
27
27
using framework::OperatorWithKernel::OperatorWithKernel;
28
28
29
29
void InferShape (framework::InferShapeContext *ctx) const override {
30
- PADDLE_ENFORCE_EQ (ctx->HasInput (" X" ), true ,
31
- " Input(X) of Op(crop_tensor) should not be null." );
32
- PADDLE_ENFORCE_EQ (ctx->HasOutput (" Out" ), true ,
33
- " Output(Out) of Op(crop_tensor) should not be null." );
30
+ OP_INOUT_CHECK (ctx->HasInput (" X" ), " Input" , " X" , " CropTensor" );
31
+ OP_INOUT_CHECK (ctx->HasOutput (" Out" ), " Output" , " Out" , " CropTensor" );
34
32
auto x_dim = ctx->GetInputDim (" X" );
35
33
auto shape = ctx->Attrs ().Get <std::vector<int >>(" shape" );
36
34
auto offsets = ctx->Attrs ().Get <std::vector<int >>(" offsets" );
@@ -39,9 +37,11 @@ class CropTensorOp : public framework::OperatorWithKernel {
39
37
auto inputs_name = ctx->Inputs (" ShapeTensor" );
40
38
PADDLE_ENFORCE_GT (
41
39
inputs_name.size (), 0 ,
42
- " Input(ShapeTensor)'size of Op(crop_tensor) can't be zero. "
43
- " Please check the Attr(shape)'s size of "
44
- " Op(fluid.layers.crop_tensor)." );
40
+ platform::errors::InvalidArgument (
41
+ " The number of elements of the input 'ShapeTensor' for "
42
+ " CropTensor must be greater than zero, "
43
+ " but the value received is %d." ,
44
+ inputs_name.size ()));
45
45
auto out_dims = std::vector<int >(inputs_name.size (), -1 );
46
46
for (size_t i = 0 ; i < shape.size (); ++i) {
47
47
if (shape[i] > 0 ) {
@@ -59,16 +59,18 @@ class CropTensorOp : public framework::OperatorWithKernel {
59
59
60
60
if (ctx->HasInput (" Shape" )) {
61
61
auto shape_dim = ctx->GetInputDim (" Shape" );
62
- PADDLE_ENFORCE_EQ (
63
- shape_dim.size (), 1 ,
64
- " Input(Shape)'s dimension size of Op(crop_tensor) must be 1. "
65
- " Please check the Attr(shape)'s dimension size of "
66
- " Op(fluid.layers.crop_tensor)." );
62
+ PADDLE_ENFORCE_EQ (shape_dim.size (), 1 ,
63
+ platform::errors::InvalidArgument (
64
+ " The number of dimensions of the input "
65
+ " 'Shape' for CropTensor must be 1, "
66
+ " but the value received is %d." ,
67
+ shape_dim.size ()));
67
68
PADDLE_ENFORCE_EQ (shape_dim[0 ], x_dim.size (),
68
- " Input(Shape)'s size of Op(crop_tensor) must be equal "
69
- " to dimension size of input tensor. "
70
- " Please check the Attr(shape)'s size of "
71
- " Op(fluid.layers.crop_tensor)." );
69
+ platform::errors::InvalidArgument (
70
+ " The number of elements (%d) of the input 'Shape' "
71
+ " for CropTensor must be equal to the number of"
72
+ " dimensions (%d) of the input." ,
73
+ shape_dim[0 ], x_dim.size ()));
72
74
if (ctx->IsRuntime ()) {
73
75
// If true, set the shape of Output(Out) according to Input(Shape) in
74
76
// CropTensorKernel with ExecutionContext. Also check LoD in
@@ -80,9 +82,13 @@ class CropTensorOp : public framework::OperatorWithKernel {
80
82
}
81
83
return ;
82
84
}
83
- PADDLE_ENFORCE_EQ (int64_t (shape.size ()), x_dim.size (),
84
- " Attr(shape)'size of Op(crop_tensor) should be equal to "
85
- " dimension size of input tensor." );
85
+ PADDLE_ENFORCE_EQ (
86
+ int64_t (shape.size ()), x_dim.size (),
87
+ platform::errors::InvalidArgument (
88
+ " The number of elements (%d) of attribute 'shape' for "
89
+ " CropTensor must be equal to the number of "
90
+ " dimensions (%d) of the input." ,
91
+ shape.size (), x_dim.size ()));
86
92
std::vector<int64_t > out_shape (shape.size (), -1 );
87
93
for (size_t i = 0 ; i < shape.size (); ++i) {
88
94
if (shape[i] > 0 ) {
@@ -242,10 +248,9 @@ class CropTensorOpGrad : public framework::OperatorWithKernel {
242
248
using framework::OperatorWithKernel::OperatorWithKernel;
243
249
244
250
void InferShape (framework::InferShapeContext *ctx) const override {
245
- PADDLE_ENFORCE_EQ (ctx->HasInput (" X" ), true ,
246
- " Input(X) of Op(crop_tensor) should not be null." );
247
- PADDLE_ENFORCE_EQ (ctx->HasInput (framework::GradVarName (" Out" )), true ,
248
- " Input(Out@GRAD) of Op(crop_tensor) should not be null." );
251
+ OP_INOUT_CHECK (ctx->HasInput (" X" ), " Input" , " X" , " CropTensorGrad" );
252
+ OP_INOUT_CHECK (ctx->HasInput (framework::GradVarName (" Out" )), " Input" ,
253
+ framework::GradVarName (" Out" ), " CropTensorGrad" );
249
254
auto x_dims = ctx->GetInputDim (" X" );
250
255
auto x_grad_name = framework::GradVarName (" X" );
251
256
if (ctx->HasOutput (x_grad_name)) {
0 commit comments