大蒟蒻 2022-04-21 12:08
浏览 95
已结题

tensorflow计算auc时出现报错

问题遇到的现象和发生背景

俺在训练nlp模型时遇到报错

问题相关代码,请勿粘贴截图
def auc(y_true, y_pred):
    auc = tf.keras.metrics.AUC(y_true, y_pred)[1]
    K.get_session().run(tf.local_variables_initializer())
    return auc
运行结果及报错内容

C:\Users\41029\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\training.py:806 train_function *
return step_function(self, iterator)
F:/项目/nlp项目主要代码/主要代码/imdb/baseline/cnn.py:179 auc *
auc = tf.keras.metrics.AUC(y_true, y_pred)[1]
C:\Users\41029\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\metrics.py:1934 init **
if num_thresholds <= 1:
C:\Users\41029\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\framework\ops.py:877 bool
self._disallow_bool_casting()
C:\Users\41029\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\framework\ops.py:486 _disallow_bool_casting
self._disallow_when_autograph_enabled(
C:\Users\41029\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\framework\ops.py:472 _disallow_when_autograph_enabled
raise errors.OperatorNotAllowedInGraphError(

OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 4月29日
    • 创建了问题 4月21日

    悬赏问题

    • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
    • ¥15 神经网络模型一直不能上GPU
    • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
    • ¥20 wpf datagrid单元闪烁效果失灵
    • ¥15 券商软件上市公司信息获取问题
    • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
    • ¥15 Android studio AVD启动不了
    • ¥15 陆空双模式无人机怎么做
    • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
    • ¥15 C#中的编译平台的区别影响