解决AttributeError module tensorflow has no attribute placeholder
这个错误通常是因为TensorFlow的版本问题导致的。在TensorFlow 2.0及以上版本中,placeholder已被弃用,因此无法使用。
解决方法:
-
将TensorFlow版本降至1.x版本,即可使用
placeholder。 -
使用
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/bKlL 著作权归作者所有。请勿转载和采集!