Skip to content

Commit ea2c498

Browse files
authored
Fix err message (#24507)
* fix error message, test=develop
1 parent 4ec7287 commit ea2c498

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

paddle/fluid/operators/pixel_shuffle_op.cc

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@ class PixelShuffleOp : public framework::OperatorWithKernel {
2020
using framework::OperatorWithKernel::OperatorWithKernel;
2121

2222
void InferShape(framework::InferShapeContext* ctx) const override {
23-
PADDLE_ENFORCE(ctx->HasInput("X"),
24-
"Input(X) of PixelShuffleOp should not be null.");
25-
PADDLE_ENFORCE(ctx->HasOutput("Out"),
26-
"Output(Out) of PixelShuffleOp should not be null.");
23+
PADDLE_ENFORCE_EQ(ctx->HasInput("X"), true,
24+
platform::errors::NotFound(
25+
"Input(X) of PixelShuffleOp should not be null."));
26+
PADDLE_ENFORCE_EQ(ctx->HasOutput("Out"), true,
27+
platform::errors::NotFound(
28+
"Output(Out) of PixelShuffleOp should not be null."));
2729

2830
auto input_dims = ctx->GetInputDim("X");
29-
PADDLE_ENFORCE(input_dims.size() == 4, "The layout of input is NCHW.");
31+
PADDLE_ENFORCE_EQ(
32+
input_dims.size(), 4,
33+
platform::errors::InvalidArgument(
34+
"Input should be a 4-D tensor of format [N, C, H, W], but got %u.",
35+
input_dims.size()));
36+
3037
auto upscale_factor = ctx->Attrs().Get<int>("upscale_factor");
3138

32-
PADDLE_ENFORCE(input_dims[1] % (upscale_factor * upscale_factor) == 0,
33-
"Upscale_factor should devide the number of channel");
39+
PADDLE_ENFORCE_EQ(input_dims[1] % (upscale_factor * upscale_factor), 0,
40+
platform::errors::InvalidArgument(
41+
"The square of upscale_factor[%u] should divide the "
42+
"number of channel[%u]",
43+
input_dims[1], upscale_factor * upscale_factor));
3444

3545
auto output_dims = input_dims;
3646
output_dims[0] = input_dims[0];
@@ -57,7 +67,8 @@ class PixelShuffleOpMaker : public framework::OpProtoAndCheckerMaker {
5767
.SetDefault(1)
5868
.AddCustomChecker([](const int& upscale_factor) {
5969
PADDLE_ENFORCE_GE(upscale_factor, 1,
60-
"upscale_factor should be larger than 0.");
70+
platform::errors::InvalidArgument(
71+
"upscale_factor should be larger than 0."));
6172
});
6273

6374
AddComment(R"DOC(
@@ -95,13 +106,19 @@ class PixelShuffleGradOp : public framework::OperatorWithKernel {
95106
using framework::OperatorWithKernel::OperatorWithKernel;
96107

97108
void InferShape(framework::InferShapeContext* ctx) const override {
98-
PADDLE_ENFORCE(ctx->HasInput(framework::GradVarName("Out")),
99-
"Input(Out@Grad) should not be null");
100-
PADDLE_ENFORCE(ctx->HasOutput(framework::GradVarName("X")),
101-
"Output(X@Grad) should not be null");
109+
PADDLE_ENFORCE_EQ(
110+
ctx->HasInput(framework::GradVarName("Out")), true,
111+
platform::errors::NotFound("Input(Out@Grad) should not be null"));
112+
PADDLE_ENFORCE_EQ(
113+
ctx->HasOutput(framework::GradVarName("X")), true,
114+
platform::errors::NotFound("Output(X@Grad) should not be null"));
102115

103116
auto do_dims = ctx->GetInputDim(framework::GradVarName("Out"));
104-
PADDLE_ENFORCE(do_dims.size() == 4, "The layout of input is NCHW.");
117+
PADDLE_ENFORCE_EQ(
118+
do_dims.size(), 4,
119+
platform::errors::InvalidArgument(
120+
"Input should be a 4-D tensor of format [N, C, H, W], but got %u.",
121+
do_dims.size()));
105122

106123
auto upscale_factor = ctx->Attrs().Get<int>("upscale_factor");
107124

python/paddle/fluid/layers/nn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13452,6 +13452,7 @@ def pixel_shuffle(x, upscale_factor):
1345213452

1345313453
"""
1345413454

13455+
check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'pixel_shuffle')
1345513456
helper = LayerHelper("pixel_shuffle", **locals())
1345613457

1345713458
out = helper.create_variable_for_type_inference(dtype=x.dtype)

0 commit comments

Comments
 (0)