-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
add crop_tensor_op #19314
add crop_tensor_op #19314
Conversation
773fb42
to
5ee3da9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add python API test in test_layers.py
@@ -0,0 +1,269 @@ | |||
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2018 -> 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
- add python API test in test_layers.py
- modified
Copyright (c) 2018
toCopyright (c) 2019
of 4 files: crop_tensor_op.cc、crop_tensor_op.cu、crop_tensor_op.h、test_crop_tensor_op.py
b39085c
to
5bc8cf2
Compare
using framework::OperatorWithKernel::OperatorWithKernel; | ||
|
||
void InferShape(framework::InferShapeContext *ctx) const override { | ||
PADDLE_ENFORCE(ctx->HasInput("X"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PADDLE_ENFORCE都需要改为其他接口,PADDLE_ENFORCE_GT等
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
python/paddle/fluid/layers/nn.py
Outdated
assert unk_dim_idx == -1, ( | ||
"Only one element in shape can be unknown.") | ||
assert dim_idx == 0, ( | ||
"Only the first element in shape can be -1.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么限制只能是第一个元素?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第一维是batch size,可以感觉输入得到。在其他维度如果出现-1,crop_tensor操作并不能根据已知的维度推断这个-1所在的维度应该是多少。原有的crop同样不支持第一维之外的其他维度为-1。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们的batch size 一定要第一维么。。还是这个op就有这种要求
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前保持原始crop的逻辑。-1的意义已和佳军沟通,进一步确认需求后再进行修改。本次PR只修改参数支持tensor
929c52c
to
97b8bcd
Compare
@@ -8971,6 +8975,152 @@ def crop(x, shape=None, offsets=None, name=None): | |||
return out | |||
|
|||
|
|||
def crop_tensor(x, shape=None, offsets=None, name=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新接口就叫做crop_tensor么
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的
python/paddle/fluid/layers/nn.py
Outdated
element of list can be a integer or a tensor Variable with shape: [1]. | ||
This way is suitable for the case that the shape may be changed each | ||
iteration. | ||
offsets (Variable|list/tuple of integer|None): Specifies the cropping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offset 不可以为 list(Variable)么
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改后已支持offset为list(Variable)
python/paddle/fluid/layers/nn.py
Outdated
assert unk_dim_idx == -1, ( | ||
"Only one element in shape can be unknown.") | ||
assert dim_idx == 0, ( | ||
"Only the first element in shape can be -1.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们的batch size 一定要第一维么。。还是这个op就有这种要求
|
||
.. code-block:: text | ||
|
||
* Case 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是可以给一个3D的例子
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 这个op的应用场景主要是图像领域,batch size通常在第一维
- 在文档中添加了3-D的例子
测试了Python接口,offsets使用存在一些问题,已反馈。 |
ac1a46d
to
e420249
Compare
已增加offset支持list(variable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ff8098d
e420249
to
ff8098d
Compare
7013690
ff8098d
to
7013690
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
7013690
to
416b211
Compare
416b211
to
4f09abb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…#19314) add crop_tensor op. The main difference with crop is : 1. If the argument shape is a list, each element is an integer or a tensor variable with shape: [1]. This way is suitable for the case that the shape may be changed each iteration. 2. If the argument shape is a variable. Its rank must be 1. In crop op, the rank of shape must be the same as x offsets can be a list, in which each element is an integer or a tensor variavle with shape: [1].
…#19314) add crop_tensor op. The main difference with crop is : 1. If the argument shape is a list, each element is an integer or a tensor variable with shape: [1]. This way is suitable for the case that the shape may be changed each iteration. 2. If the argument shape is a variable. Its rank must be 1. In crop op, the rank of shape must be the same as x offsets can be a list, in which each element is an integer or a tensor variavle with shape: [1].
add
crop_tensor
op. The main difference withcrop
is :shape
is a list, each element is an integer or a tensor variable with shape: [1]. This way is suitable for the case that the shape may be changed each iteration.shape
is a variable. Its rank must be 1. Incrop
op, the rank ofshape
must be the same asx
offsets
can be a list, in which each element is an integer or a tensor variavle with shape: [1].