reduce_sum如何只输出常量,不要带维度
Created by: yeyupiaoling
环境
- PaddlePaddle (develop)
- Ubuntu 16.04
- Python 3.5
问题
我希望得到的是通过reduce_sum
接口后得到一个常量,但是这接口得到的是维度为1的。
num_valid = fluid.layers.reduce_sum(valid_inds)
因为我下面需要计算
# 选取70%的数据
num_keep_radio = 0.7
keep_num = fluid.layers.squeeze(fluid.layers.cast(num_valid * num_keep_radio, dtype='int32'), axes=[])
num_valid的信息:
name: "reduce_sum_0.tmp_0"
type {
type: LOD_TENSOR
lod_tensor {
tensor {
data_type: FP32
dims: 1
}
}
}
persistable: false
会报错:
C++ Callstacks:
The shape information must be set by Attr(shape). at [/paddle/paddle/fluid/operators/reshape_op.cc:37]
PaddlePaddle Call Stacks: