问题遇到的现象和发生背景
俺在训练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.