这个错误通常是因为 TensorFlow 的版本问题导致的。在 TensorFlow 2.0 及以上版本中,'placeholder' 已被弃用,因此无法使用。

解决方法:

  1. 将 TensorFlow 版本降至 1.x 版本,即可使用 'placeholder'。

  2. 使用 'tf.compat.v1.placeholder' 代替 'tf.placeholder',这样可以在 TensorFlow 2.0 及以上版本中使用 'placeholder'。例如:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

x = tf.placeholder(tf.float32, shape=[None, 784])

注意:虽然这种方法可以在 TensorFlow 2.0 及以上版本中使用 'placeholder',但是不推荐使用,因为 'placeholder' 已被弃用,建议使用 'tf.data.Dataset' 代替。


原文地址: https://www.cveoy.top/t/topic/jszF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录