Skip to content

Conversation

@shiwenguo
Copy link

@shiwenguo shiwenguo commented Feb 24, 2018

fixes #8131

@shiwenguo shiwenguo changed the title resolve #8138 resolve #8131 Feb 24, 2018
@lcy-seso lcy-seso self-requested a review February 26, 2018 03:58
@lcy-seso lcy-seso changed the title resolve #8131 Add squeeze and unsqueeze operator. Mar 2, 2018
AddAttr<std::vector<int>>("axes",
"(vector<int>) "
"List of positive integers,"
"indicate the dimensions to squeeze.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. line 58 ~ line 60 合并一下。
  2. 注释请严格follow Fluid的注释标准,遵循 (type,default value) usage的注释编写原则。
  3. 请为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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Takes --> take.
  2. a list of axes --> a list of axis

@@ -0,0 +1,96 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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 这个值太大了。可以删掉这个设置,使用默认值。

@lcy-seso
Copy link
Contributor

lcy-seso commented Mar 2, 2018

Squeeze 和 Unsqueeze 可以在Python端通过wrap reshape实现,在C++端不需要添加这两个 operator 。抱歉,我在创建最初的issue时,没有解释清楚。

@lcy-seso
Copy link
Contributor

lcy-seso commented Mar 2, 2018

经过和 @shiwenguo 商量,决定将 squeeze 和 unsqueeze operator 放在 Python 端,通过wrap reshape operator 来实现。不 merge 此 PR。

@luotao1
Copy link
Contributor

luotao1 commented Feb 1, 2019

Close due to squeeze_op and unsqueeze_op have already been done.

@luotao1 luotao1 closed this Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Impelment squeeze and unsqueeze operator.

3 participants