Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance error message for interpolate_v2 #33941

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion paddle/fluid/operators/interpolate_v2_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ static void Interpolate1DInferShapeCheck(framework::InferShapeContext* ctx) {
interp_method));
const DataLayout data_layout = framework::StringToDataLayout(
ctx->Attrs().Get<std::string>("data_layout"));

for (int i = 0; i < dim_x.size(); ++i) {
PADDLE_ENFORCE_NE(dim_x[i], 0, platform::errors::InvalidArgument(
"The shape of input(x) should be larged "
"than 0, bug received shape[%d] is %d ",
i, dim_x[i]));
}
if (ctx->HasInputs("SizeTensor")) {
// top prority size
auto inputs_name = ctx->Inputs("SizeTensor");
Expand Down Expand Up @@ -134,6 +139,13 @@ static void Interpolate2DInferShapeCheck(framework::InferShapeContext* ctx) {
const DataLayout data_layout = framework::StringToDataLayout(
ctx->Attrs().Get<std::string>("data_layout"));

for (int i = 0; i < dim_x.size(); ++i) {
PADDLE_ENFORCE_NE(dim_x[i], 0, platform::errors::InvalidArgument(
"The shape of input(x) should be larged "
"than 0, bug received shape[%d] is %d ",
i, dim_x[i]));
}

if (ctx->HasInputs("SizeTensor")) {
// top prority size
auto inputs_name = ctx->Inputs("SizeTensor");
Expand Down Expand Up @@ -246,6 +258,13 @@ static void Interpolate3DInferShapeCheck(framework::InferShapeContext* ctx) {
const DataLayout data_layout = framework::StringToDataLayout(
ctx->Attrs().Get<std::string>("data_layout"));

for (int i = 0; i < dim_x.size(); ++i) {
PADDLE_ENFORCE_NE(dim_x[i], 0, platform::errors::InvalidArgument(
"The shape of input(x) should be larged "
"than 0, bug received shape[%d] is %d ",
i, dim_x[i]));
}

if (ctx->HasInputs("SizeTensor")) {
// top prority size
auto inputs_name = ctx->Inputs("SizeTensor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ def test_size_type():
out = interpolate(
x, size={2, 2}, mode='bicubic', align_corners=False)

def test_input_shape():
x = fluid.data(name="x", shape=[2, 1, 0, 0], dtype="float32")
out = interpolate(
x, size=[3, 3], mode="bicubic", align_corners=False)

self.assertRaises(ValueError, test_mode_type)
self.assertRaises(ValueError, test_input_shape)
self.assertRaises(TypeError, test_align_corcers)
Expand All @@ -534,6 +539,7 @@ def test_size_type():
self.assertRaises(ValueError, test_size_and_scale)
self.assertRaises(ValueError, test_size_and_scale2)
self.assertRaises(TypeError, test_size_type)
self.assertRaises(ValueError, test_input_shape)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import paddle.fluid as fluid
from paddle.nn.functional import interpolate

np.random.seed(123)


def trilinear_interp_np(input,
out_d,
Expand Down