Tensorflow中流式F1分数计算中的数据类型不匹配

时间:2019-06-03 10:02:34

标签: tensorflow tensorflow-estimator

我试图像在Tensorflow 1.13.1上一样使用this code。但是,它引发以下错误:

sherlock@mybox:~/cs273/autocat/bert$ python streaming2.py 
Traceback (most recent call last):
  File "streaming2.py", line 233, in <module>
    tf_f1 = tf_f1_score(t, p)
  File "streaming2.py", line 161, in tf_f1_score
    f1s[2] = tf.reduce_sum(f1 * weights)
  File "/home/sherlock/.virtualenvs/autocat/local/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 812, in binary_op_wrapper
    return func(x, y, name=name)
  File "/home/sherlock/.virtualenvs/autocat/local/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 1078, in _mul_dispatch
    return gen_math_ops.mul(x, y, name=name)
  File "/home/sherlock/.virtualenvs/autocat/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 5860, in mul
    "Mul", x=x, y=y, name=name)
  File "/home/sherlock/.virtualenvs/autocat/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 547, in _apply_op_helper
    inferred_from[input_arg.type_attr]))
TypeError: Input 'y' of 'Mul' Op has type float64 that does not match type int64 of argument 'x'.

尝试修复类型转换一段时间,但未能找到使代码正常工作的最小更改。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

我可以重现您的错误:它在Python 2中发生,但不是在3中发生。

所以要么切换到Python 3,要么用tf.cast更改代码

window.addEventListener("load", function() {
    alert("Called on page load");
}, false);

也许在其他地方,但这就是主意