-
Notifications
You must be signed in to change notification settings - Fork 5.9k
modify flip test=develop #25312
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
Merged
Merged
modify flip test=develop #25312
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ | |
| from ..fluid.layers import expand_as #DEFINE_ALIAS | ||
| from ..fluid.layers import flatten #DEFINE_ALIAS | ||
| from ..fluid.layers import reshape #DEFINE_ALIAS | ||
| from ..fluid.layers import reverse #DEFINE_ALIAS | ||
| from ..fluid.layers import scatter #DEFINE_ALIAS | ||
| from ..fluid.layers import slice #DEFINE_ALIAS | ||
| from ..fluid.layers import strided_slice #DEFINE_ALIAS | ||
|
|
@@ -51,59 +50,63 @@ | |
| ] | ||
|
|
||
|
|
||
| def flip(input, dims, name=None): | ||
| def flip(x, axis, name=None): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. axis 中某个元素是负数时也应该支持。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是支持的 我添加下注释 |
||
| """ | ||
| :alias_main: paddle.flip | ||
| :alias: paddle.flip,paddle.tensor.flip,paddle.tensor.manipulation.flip | ||
|
|
||
|
|
||
| Reverse the order of a n-D tensor along given axis in dims. | ||
| Reverse the order of a n-D tensor along given axis in axis. | ||
|
|
||
| Args: | ||
| input (Variable): A Tensor(or LoDTensor) with shape :math:`[N_1, N_2,..., N_k]` . The data type of the input Tensor | ||
| x (Variable): A Tensor(or LoDTensor) with shape :math:`[N_1, N_2,..., N_k]` . The data type of the input Tensor x | ||
yaoxuefeng6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| should be float32, float64, int32, int64, bool. | ||
| dims (list): The axis to flip on. | ||
| axis (list): The axis(axes) to flip on. Negative indices for indexing from the end are accepted. | ||
| name (str, optional): The default value is None. Normally there is no need for user to set this property. | ||
| For more information, please refer to :ref:`api_guide_Name` . | ||
|
|
||
| Returns: | ||
| Variable: Tensor or LoDTensor calculated by flip layer. The data type is same with input. | ||
| Variable: Tensor or LoDTensor calculated by flip layer. The data type is same with input x. | ||
|
|
||
| Examples: | ||
| .. code-block:: python | ||
|
|
||
| import paddle | ||
| import paddle.fluid as fluid | ||
| import numpy as np | ||
| input = fluid.data(name="x", shape=[-1, 2, 2], dtype='float32') | ||
| output = paddle.flip(input, dims=[0, 1]) | ||
| exe = fluid.Executor(fluid.CPUPlace()) | ||
| exe.run(fluid.default_startup_program()) | ||
| img = np.arange(12).reshape((3,2,2)).astype(np.float32) | ||
| res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) | ||
| print(res) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]] | ||
|
|
||
| paddle.enable_imperative() | ||
|
|
||
| image_shape=(3, 2, 2) | ||
| x = np.arange(image_shape[0] * image_shape[1] * image_shape[2]).reshape(image_shape) | ||
| x = x.astype('float32') | ||
| img = paddle.imperative.to_variable(x) | ||
| out = paddle.flip(img, [0,1]) | ||
|
|
||
| print(out) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]] | ||
| """ | ||
| helper = LayerHelper("flip", **locals()) | ||
| check_type(input, 'X', (Variable), 'flip') | ||
| dtype = helper.input_dtype() | ||
| check_type(x, 'X', (Variable), 'flip') | ||
| dtype = helper.input_dtype('x') | ||
| check_dtype(dtype, 'X', | ||
| ['float16', 'float32', 'float64', 'int32', 'int64', 'bool'], | ||
| 'flip') | ||
| check_type(dims, 'dims', (list, tuple), 'flip') | ||
| assert len(dims) > 0, 'len(dims) must be greater than 0.' | ||
| check_type(axis, 'axis', (list, tuple), 'flip') | ||
| if name is None: | ||
| out = helper.create_variable_for_type_inference(dtype) | ||
| else: | ||
| out = helper.create_variable(name=name, dtype=dtype, persistable=False) | ||
|
|
||
| helper.append_op( | ||
| type="flip", | ||
| inputs={"X": input}, | ||
| inputs={"X": x}, | ||
| outputs={"Out": out}, | ||
| attrs={"dims": dims}) | ||
| attrs={"axis": axis}) | ||
| return out | ||
|
|
||
|
|
||
| reverse = flip #DEFINE_ALIAS | ||
|
|
||
|
|
||
| def roll(x, shifts, axis=None, name=None): | ||
| """ | ||
| :alias_main: paddle.roll | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.