From b9f1f4343b0ba3a54a10b29e1739b88ae3d84142 Mon Sep 17 00:00:00 2001 From: LielinJiang <50691816+LielinJiang@users.noreply.github.com> Date: Wed, 2 Dec 2020 22:13:51 +0800 Subject: [PATCH] Move temporal_shift to paddle.nn.functional (#29261) * move temporal_shift to functional --- python/paddle/fluid/layers/nn.py | 2 +- .../fluid/tests/unittests/test_temporal_shift_op.py | 9 +++++++++ python/paddle/nn/functional/__init__.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index d2c062d1d6f..3971e2076dc 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -13348,7 +13348,7 @@ def temporal_shift(x, seg_num, shift_ratio=0.25, name=None): import paddle.nn.functional as F input = paddle.randn([6, 4, 2, 2]) - out = paddle.fluid.layers.temporal_shift(x=input, seg_num=2, shift_ratio=0.2) + out = F.temporal_shift(x=input, seg_num=2, shift_ratio=0.2) """ helper = LayerHelper("temporal_shift", **locals()) check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'temporal_shift') diff --git a/python/paddle/fluid/tests/unittests/test_temporal_shift_op.py b/python/paddle/fluid/tests/unittests/test_temporal_shift_op.py index a102bcea995..12eec2073b3 100644 --- a/python/paddle/fluid/tests/unittests/test_temporal_shift_op.py +++ b/python/paddle/fluid/tests/unittests/test_temporal_shift_op.py @@ -84,6 +84,15 @@ class TestTemporalShiftAPI(unittest.TestCase): out = paddle.fluid.layers.temporal_shift( x=input, seg_num=2, shift_ratio=0.2) + out_from_function = paddle.nn.functional.temporal_shift( + x=input, seg_num=2, shift_ratio=0.2) + + # dygraph + with paddle.fluid.dygraph.guard(): + input = paddle.randn([6, 4, 2, 2]) + out = paddle.nn.functional.temporal_shift( + x=input, seg_num=2, shift_ratio=0.2) + if __name__ == "__main__": unittest.main() diff --git a/python/paddle/nn/functional/__init__.py b/python/paddle/nn/functional/__init__.py index cec69d6998c..84bab5feff4 100644 --- a/python/paddle/nn/functional/__init__.py +++ b/python/paddle/nn/functional/__init__.py @@ -216,3 +216,4 @@ from .vision import pixel_shuffle #DEFINE_ALIAS from .input import one_hot #DEFINE_ALIAS from .input import embedding #DEFINE_ALIAS from ...fluid.layers import gather_tree +from ...fluid.layers import temporal_shift -- GitLab