未验证 提交 8ef1bf87 编写于 作者: S shangliang Xu 提交者: GitHub

[bug fix] fix unfold negative_size_param (#34943)

* [bug fix] fix unfold negative_size_param
上级 9d4f00bc
......@@ -154,6 +154,25 @@ class UnfoldOp : public framework::OperatorWithKernel {
paddings[2], strides[0]);
int output_width = CalcOutputSize(in_dims[3], kernel_sizes[1], dilations[1],
paddings[1], paddings[3], strides[1]);
// check output height and width
PADDLE_ENFORCE_GT(
output_height, 0,
platform::errors::InvalidArgument(
"The sliding blocks calculated from input spatial size (%d, %d), "
"kernel_sizes (%d, %d), strides (%d, %d), dilations (%d, %d), "
"is (%d, %d), which should be a positive integer.",
in_dims[2], in_dims[3], kernel_sizes[0], kernel_sizes[1],
strides[0], strides[1], dilations[0], dilations[1], output_height,
output_width));
PADDLE_ENFORCE_GT(
output_width, 0,
platform::errors::InvalidArgument(
"The sliding blocks calculated from input spatial size (%d, %d), "
"kernel_sizes (%d, %d), strides (%d, %d), dilations (%d, %d), "
"is (%d, %d), which should be a positive integer.",
in_dims[2], in_dims[3], kernel_sizes[0], kernel_sizes[1],
strides[0], strides[1], dilations[0], dilations[1], output_height,
output_width));
int output_col_length = output_height * output_width;
out_dims.push_back(output_col_length);
......
......@@ -3320,6 +3320,30 @@ class TestBook(LayerTest):
dy_res_value = dy_res.numpy()
self.assertTrue(np.array_equal(static_res, dy_res_value))
def test_dice_loss(self):
num_classes = 4
eps = 1e-6
input_np = np.random.rand(2, 3, num_classes).astype('float32')
label_np = np.random.randint(0, num_classes, [2, 3, 1], dtype=np.int64)
with self.static_graph():
input_ = layers.data(
name="input", shape=[None, 3, num_classes], dtype="float32")
label_ = layers.data(
name="label", shape=[None, 3, 1], dtype="int64")
output = layers.dice_loss(input_, label_, eps)
static_res = self.get_static_graph_result(
feed={'input': input_np,
'label': label_np},
fetch_list=[output])[0]
with self.dynamic_graph():
input_ = base.to_variable(input_np)
label_ = base.to_variable(label_np)
dy_res = layers.dice_loss(input_, label_, eps)
dy_res_value = dy_res.numpy()
self.assertTrue(np.array_equal(static_res, dy_res_value))
def test_roi_perspective_transform(self):
# TODO(minqiyang): dygraph do not support lod now
with self.static_graph():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册