paddlepaddle 2.0.1
执行命令:paddle.sum([True, False, True, False]) 会报错:
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paddle/tensor/math.py", line 757, in sum
'reduce_all', reduce_all_flag)
ValueError: (InvalidArgument) reduce_sum(): argument 'X' (position 0) must be Tensor, but got list (at /home/teamcity/work/ef54dc8a5b211854/paddle/fluid/pybind/op_function.h:56)
需求场景:
在分类训练时累计预测正确数,希望可以这样写:
acc = paddle.sum(paddle.argmax(preds, axis=1) == labels[:, 0])
1条答案
按热度按时间a1o7rhls1#
可以使用
cast
或者where
op将bool型的数值转为数值型,参与后续运算