未验证 提交 f2068eec 编写于 作者: X xiaoting 提交者: GitHub

Enhance error message for interpolate_v2 (#33941)

* fix interpolate for shape[i]=0, test=develop

* fix test_trilinear_interp_v2 random failure, test=develop
上级 bfef7feb
......@@ -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");
......@@ -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");
......@@ -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");
......
......@@ -517,6 +517,11 @@ class TestBicubicOpError(unittest.TestCase):
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)
......@@ -534,6 +539,7 @@ class TestBicubicOpError(unittest.TestCase):
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__":
......
......@@ -21,6 +21,8 @@ import paddle.fluid.core as core
import paddle.fluid as fluid
from paddle.nn.functional import interpolate
np.random.seed(123)
def trilinear_interp_np(input,
out_d,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册