-
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
reduce_sum如何只输出常量,不要带维度 #16507
Comments
scalar也是一个dim=[1]的tensor,并且squeeze layer是从input 中去掉axes指定纬度的数据。 另外请问下“# 选取70%的数据” 是指什么方式选取,希望的输出是什么样子的呢? |
这个是MTCNN模型的是否有人脸的分类交叉熵函数,在训练过程中,为了取得更好的效果,作者每次只后向传播前70%样本的梯度,这样来保证传递的都是有效的数字。 |
@Yancey1989 如果修改成以下这样,还是报错 # 选取70%的数据
num_keep_radio = 0.7
num_valid = fluid.layers.squeeze(input=num_valid, axes=[])
keep_num = fluid.layers.squeeze(fluid.layers.cast(num_valid * num_keep_radio, dtype='int32'), axes=[]) 报错如下:
这个rank到底是指什么?还有项目中直接执行 |
原因在:
这个报错的原因应该是reshape op没有指定shape吧? |
@Yancey1989 如果不设置的话就会报一开始的错误, 如果我修改成如下的话,报的错跟一开始的错误。
|
>>> num_keep_radio = fluid.layers.fill_constant(shape=[1], dtype='float32', value=0.7)
>>> valid_inds=fluid.layers.data(name="x", shape=[10])
>>> num_valid = fluid.layers.reduce_sum(valid_inds)
>>> keep_num = fluid.layers.squeeze(fluid.layers.cast(num_valid * num_keep_radio, dtype='int32'), axes=[]) 这个是正常的,没有报错。
更一开始的错误是什么呢? |
已经修改:报的错跟一开始的错误。 |
@Yancey1989 我再琢磨琢磨吧。谢谢 |
@yeyupiaoling 欢迎试用并安装develop 版本的paddle whl包,将体验最新的0维特性:https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html Hello, Paddle will fully support the 0-dimensional Tensor in version 2.5, and the 0D issue will also be resolved at the same time. |
环境
问题
我希望得到的是通过
reduce_sum
接口后得到一个常量,但是这接口得到的是维度为1的。因为我下面需要计算
num_valid的信息:
会报错:
项目代码:https://github.com/yeyupiaoling/TestMTCNN/blob/a04126361fa0918f78420e3ce29c77bf8b97aede/train/model.py#L157-L159
The text was updated successfully, but these errors were encountered: