未验证 提交 9089841b 编写于 作者: L LielinJiang 提交者: GitHub

Fix bilateral inference shape bug (#26822)

* fix bilateral bug
上级 5345a588
......@@ -50,20 +50,25 @@ class BilateralSliceOp : public framework::OperatorWithKernel {
int64_t input_chans = input_dims[1];
int64_t output_chans;
if (has_offset) {
PADDLE_ENFORCE_EQ((coeffs_chans % (input_chans + 1)), 0,
platform::errors::InvalidArgument(
"Slicing with affine offset, coefficients grid "
"should have n_out*(n_in+1) channels, but got %d",
coeffs_chans));
output_chans = coeffs_chans / (input_chans + 1);
if ((!ctx->IsRuntime()) && ((coeffs_chans < 0) || (input_chans < 0))) {
output_chans = -1;
} else {
PADDLE_ENFORCE_EQ((coeffs_chans % input_chans), 0,
platform::errors::InvalidArgument(
"Slicing without affine offset, coefficients grid "
"should have n_out*n_in channels, but got %d .",
coeffs_chans));
output_chans = coeffs_chans / input_chans;
if (has_offset) {
PADDLE_ENFORCE_EQ((coeffs_chans % (input_chans + 1)), 0,
platform::errors::InvalidArgument(
"Slicing with affine offset, coefficients grid "
"should have n_out*(n_in+1) channels, but got %d",
coeffs_chans));
output_chans = coeffs_chans / (input_chans + 1);
} else {
PADDLE_ENFORCE_EQ(
(coeffs_chans % input_chans), 0,
platform::errors::InvalidArgument(
"Slicing without affine offset, coefficients grid "
"should have n_out*n_in channels, but got %d .",
coeffs_chans));
output_chans = coeffs_chans / input_chans;
}
}
std::vector<int64_t> output_dims;
......
......@@ -1525,10 +1525,10 @@ def bilateral_slice(x, guide, grid, has_offset, name=None):
grid = fluid.data(name='grid', shape=[None, 12, 8, 10, 6], dtype='float32')
# without offset
output = fluid.layers.bilateral_slice(x, guide, grid, has_offset=False)
output = fluid.contrib.bilateral_slice(x, guide, grid, has_offset=False)
# has offset
output = fluid.layers.bilateral_slice(x, guide, grid, has_offset=True)
output = fluid.contrib.bilateral_slice(x, guide, grid, has_offset=True)
"""
helper = LayerHelper("bilateral_slice", **locals())
......@@ -1541,7 +1541,9 @@ def bilateral_slice(x, guide, grid, has_offset, name=None):
out = helper.create_variable_for_type_inference(x.dtype)
inputs = {'X': x, 'Guide': guide, 'Grid': grid}
if paddle.fluid.in_dygraph_mode():
attrs = ('has_offset', has_offset)
return getattr(core.ops, "bilateral_slice")(x, grid, guide, *attrs)
helper.append_op(
type='bilateral_slice',
inputs=inputs,
......
......@@ -178,16 +178,25 @@ class TestBilateralSliceOp1(TestBilateralSliceOp):
self.data_type = 'float32'
class TestBilateralSliceApi(TestBilateralSliceOp):
class TestBilateralSliceApi(unittest.TestCase):
def test_api(self):
x = paddle.fluid.data(
name='x', shape=[None, 3, 25, 15], dtype='float32')
guide = paddle.fluid.data(
name='guide', shape=[None, 25, 15], dtype='float32')
grid = paddle.fluid.data(
name='grid', shape=[None, 12, 8, 5, 3], dtype='float32')
paddle.fluid.contrib.layers.bilateral_slice(x, guide, grid,
self.has_offset)
name='grid', shape=[None, None, 8, 5, 3], dtype='float32')
paddle.fluid.contrib.layers.bilateral_slice(x, guide, grid, False)
if not paddle.fluid.is_compiled_with_cuda():
return
with paddle.fluid.dygraph.guard():
x1 = paddle.rand([3, 1, 50, 30])
guide1 = paddle.rand([3, 50, 30])
grid1 = paddle.rand([3, 2, 2, 5, 3])
paddle.fluid.contrib.bilateral_slice(x1, guide1, grid1, False)
if __name__ == "__main__":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册