module 'tensorflow' has no attribute 'placeholder'
时间: 2023-09-20 21:08:44 浏览: 100
This error occurs when you are using Tensorflow 2.x version which does not have the attribute `placeholder`. In Tensorflow 2.x, the recommended way to feed data into a model is by using the `tf.data` API.
If you want to use the `placeholder` in Tensorflow 1.x, you need to downgrade your Tensorflow version or use the compatibility module `tensorflow.compat.v1`. Here is an example code to create a placeholder in Tensorflow 1.x using the compatibility module:
```
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# Create a placeholder for input data
input_data = tf.placeholder(tf.float32, shape=[None, 784], name='input_data')
```
Note that the above code will not work in Tensorflow 2.x. If you want to use Tensorflow 2.x, you need to use the `tf.data` API for feeding data into the model.
阅读全文