@@ -19,15 +19,27 @@ class DensityPriorBoxOp : public framework::OperatorWithKernel {
19
19
using framework::OperatorWithKernel::OperatorWithKernel;
20
20
21
21
void InferShape (framework::InferShapeContext* ctx) const override {
22
- PADDLE_ENFORCE (ctx->HasInput (" Input" ),
23
- " Input(Input) of DensityPriorBoxOp should not be null. " );
24
- PADDLE_ENFORCE (ctx->HasInput (" Image" ),
25
- " Input(Image) of DensityPriorBoxOp should not be null. " );
22
+ OP_INOUT_CHECK (ctx->HasInput (" Input" ), " Input " , " Input " ,
23
+ " DensityPriorBoxOp" );
24
+ OP_INOUT_CHECK (ctx->HasInput (" Image" ), " Input " , " Image " ,
25
+ " DensityPriorBoxOp" );
26
26
27
27
auto image_dims = ctx->GetInputDim (" Image" );
28
28
auto input_dims = ctx->GetInputDim (" Input" );
29
- PADDLE_ENFORCE (image_dims.size () == 4 , " The layout of image is NCHW." );
30
- PADDLE_ENFORCE (input_dims.size () == 4 , " The layout of input is NCHW." );
29
+ PADDLE_ENFORCE_EQ (
30
+ image_dims.size (), 4 ,
31
+ platform::errors::InvalidArgument (
32
+ " The Input(Image) of Op(density_prior_box) should be a 4-D Tensor "
33
+ " and data format is NCHW. But received Image's dimensions = %d, "
34
+ " shape = [%s]." ,
35
+ image_dims.size (), image_dims));
36
+ PADDLE_ENFORCE_EQ (
37
+ input_dims.size (), 4 ,
38
+ platform::errors::InvalidArgument (
39
+ " The Input(Input) of Op(density_prior_box) should be a 4-D Tensor "
40
+ " and data format is NCHW. But received Input's dimensions = %d, "
41
+ " shape = [%s]." ,
42
+ input_dims.size (), input_dims));
31
43
32
44
if (ctx->IsRuntime ()) {
33
45
PADDLE_ENFORCE_LT (
@@ -53,8 +65,13 @@ class DensityPriorBoxOp : public framework::OperatorWithKernel {
53
65
auto densities = ctx->Attrs ().Get <std::vector<int >>(" densities" );
54
66
bool flatten = ctx->Attrs ().Get <bool >(" flatten_to_2d" );
55
67
56
- PADDLE_ENFORCE_EQ (fixed_sizes.size (), densities.size (),
57
- " The number of fixed_sizes and densities must be equal." );
68
+ PADDLE_ENFORCE_EQ (
69
+ fixed_sizes.size (), densities.size (),
70
+ platform::errors::InvalidArgument (
71
+ " The length of fixed_sizes and densities must be equal. "
72
+ " But received: fixed_sizes's length is %d, densities's length "
73
+ " is %d" ,
74
+ fixed_sizes.size (), densities.size ()));
58
75
size_t num_priors = 0 ;
59
76
for (size_t i = 0 ; i < densities.size (); ++i) {
60
77
num_priors += (fixed_ratios.size ()) * (pow (densities[i], 2 ));
@@ -110,10 +127,16 @@ class DensityPriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
110
127
" encoded in density prior boxes." )
111
128
.AddCustomChecker ([](const std::vector<float >& variances) {
112
129
PADDLE_ENFORCE_EQ (variances.size (), 4 ,
113
- " Must and only provide 4 variance." );
130
+ platform::errors::InvalidArgument (
131
+ " The length of variance must "
132
+ " be 4. But received: variances' length is %d." ,
133
+ variances.size ()));
114
134
for (size_t i = 0 ; i < variances.size (); ++i) {
115
135
PADDLE_ENFORCE_GT (variances[i], 0.0 ,
116
- " variance[%d] must be greater than 0." , i);
136
+ platform::errors::OutOfRange (
137
+ " variance[%d] must be greater "
138
+ " than 0. But received: variance[%d] = %f" ,
139
+ i, i, variances[i]));
117
140
}
118
141
});
119
142
AddAttr<bool >(" clip" , " (bool) Whether to clip out-of-boundary boxes." )
@@ -127,14 +150,22 @@ class DensityPriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
127
150
" Density prior boxes step across width, 0.0 for auto calculation." )
128
151
.SetDefault (0.0 )
129
152
.AddCustomChecker ([](const float & step_w) {
130
- PADDLE_ENFORCE_GE (step_w, 0.0 , " step_w should be larger than 0." );
153
+ PADDLE_ENFORCE_GE (step_w, 0.0 ,
154
+ platform::errors::InvalidArgument (
155
+ " step_w should be larger "
156
+ " than 0. But received: step_w = %f." ,
157
+ step_w));
131
158
});
132
159
AddAttr<float >(
133
160
" step_h" ,
134
161
" Density prior boxes step across height, 0.0 for auto calculation." )
135
162
.SetDefault (0.0 )
136
163
.AddCustomChecker ([](const float & step_h) {
137
- PADDLE_ENFORCE_GE (step_h, 0.0 , " step_h should be larger than 0." );
164
+ PADDLE_ENFORCE_GE (step_h, 0.0 ,
165
+ platform::errors::InvalidArgument (
166
+ " step_h should be larger "
167
+ " than 0. But received: step_h = %f." ,
168
+ step_h));
138
169
});
139
170
140
171
AddAttr<float >(" offset" ,
@@ -147,8 +178,12 @@ class DensityPriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
147
178
.SetDefault (std::vector<float >{})
148
179
.AddCustomChecker ([](const std::vector<float >& fixed_sizes) {
149
180
for (size_t i = 0 ; i < fixed_sizes.size (); ++i) {
150
- PADDLE_ENFORCE_GT (fixed_sizes[i], 0.0 ,
151
- " fixed_sizes[%d] should be larger than 0." , i);
181
+ PADDLE_ENFORCE_GT (
182
+ fixed_sizes[i], 0.0 ,
183
+ platform::errors::OutOfRange (
184
+ " fixed_sizes[%d] should be "
185
+ " larger than 0. But received: fixed_sizes[%d] = %f" ,
186
+ i, i, fixed_sizes[i]));
152
187
}
153
188
});
154
189
@@ -158,8 +193,12 @@ class DensityPriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
158
193
.SetDefault (std::vector<float >{})
159
194
.AddCustomChecker ([](const std::vector<float >& fixed_ratios) {
160
195
for (size_t i = 0 ; i < fixed_ratios.size (); ++i) {
161
- PADDLE_ENFORCE_GT (fixed_ratios[i], 0.0 ,
162
- " fixed_ratios[%d] should be larger than 0." , i);
196
+ PADDLE_ENFORCE_GT (
197
+ fixed_ratios[i], 0.0 ,
198
+ platform::errors::OutOfRange (
199
+ " fixed_ratios[%d] should be "
200
+ " larger than 0. But received: fixed_ratios[%d] = %f" ,
201
+ i, i, fixed_ratios[i]));
163
202
}
164
203
});
165
204
@@ -169,8 +208,12 @@ class DensityPriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
169
208
.SetDefault (std::vector<int >{})
170
209
.AddCustomChecker ([](const std::vector<int >& densities) {
171
210
for (size_t i = 0 ; i < densities.size (); ++i) {
172
- PADDLE_ENFORCE_GT (densities[i], 0 ,
173
- " densities[%d] should be larger than 0." , i);
211
+ PADDLE_ENFORCE_GT (
212
+ densities[i], 0 ,
213
+ platform::errors::OutOfRange (
214
+ " densities[%d] should be "
215
+ " larger than 0. But received: densities[%d] = %f." ,
216
+ i, i, densities[i]));
174
217
}
175
218
});
176
219
AddComment (R"DOC(
0 commit comments