Tensorflow 中流式 F1 分数计算中的数据类型不匹配 [英] Data type mismatch in streaming F1 score calculation in Tensorflow

查看:26
本文介绍了Tensorflow 中流式 F1 分数计算中的数据类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 此代码,因为它在 Tensorflow 1.13.1 上.但是,它会引发以下错误:

I was trying to use this code as it is on Tensorflow 1.13.1. However, it throws the following error:

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'.

尝试修复强制转换有一段时间了,但未能找到使代码正常工作的最小更改.任何人都可以帮我解决这个问题吗?

Tried fixing the casts for some time, but failed to find a minimal change that makes the code work. Can anyone please help me on this?

推荐答案

我可以重现您的错误:它发生在 Python 2 而不是 3.

I could reproduce your error: it happens with Python 2 but not 3.

因此,要么切换到 Python 3,要么使用 tf 更改代码.cast

So either switch to Python 3 or change the code with tf.cast

f1 = tf.cast(f1, tf.float64)
f1s[2] = tf.reduce_sum(f1 * weights)

也许在其他地方,但这就是想法

and maybe in other locations but that's the idea

这篇关于Tensorflow 中流式 F1 分数计算中的数据类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆