-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add squeeze and unsqueeze operator. #8541
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
Conversation
| AddAttr<std::vector<int>>("axes", | ||
| "(vector<int>) " | ||
| "List of positive integers," | ||
| "indicate the dimensions to squeeze.") |
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.
- line 58 ~ line 60 合并一下。
- 注释请严格follow Fluid的注释标准,遵循
(type,default value) usage的注释编写原则。 - 请为
axes这个attribute调用.SetDefault(xx)提供一个默认值。从计算逻辑上,这个attribute是optional的。
| Squeeze Operator. | ||
|
|
||
| Remove single-dimensional entries from the shape of a tensor. | ||
| Takes a parameter axes with a list of axes to squeeze. |
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.
- Takes --> take.
- a list of axes --> a list of axis
| @@ -0,0 +1,96 @@ | |||
| /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | |||
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.
关于unsqueeze operator这里我有一个问题。
Unsqueeze的计算逻辑应该可以通过直接使用reshape operator来实现。也就是只需要在python端添加fluid.layer.unsqueeze在Python端计算好unsqueezed之后的实际输出shape,调用reshape operator,可以实现unsqueeze的逻辑。
|
|
||
| out->mutable_data<T>(context.GetPlace()); | ||
| framework::TensorCopy(*in, context.GetPlace(), context.device_context(), | ||
| out); |
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.
line 29 先获取 out 的dims,34行又将 resize 为获取到的dims。为什么需要这个操作呢?
| self.check_output() | ||
|
|
||
| def test_check_grad(self): | ||
| self.check_grad(["X"], "Out", max_relative_error=0.5) |
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.
max_relative_error=0.5 这个值太大了。可以删掉这个设置,使用默认值。
|
Squeeze 和 Unsqueeze 可以在Python端通过wrap reshape实现,在C++端不需要添加这两个 operator 。抱歉,我在创建最初的issue时,没有解释清楚。 |
|
经过和 @shiwenguo 商量,决定将 squeeze 和 unsqueeze operator 放在 Python 端,通过wrap reshape operator 来实现。不 merge 此 PR。 |
|
Close due to squeeze_op and unsqueeze_op have already been done. |
fixes #8131