I’m learning TensorFlow 2.x and I have some code from TF 1.x:
X = tf.placeholder(tf.float32, shape=[None, 784])
Y = tf.placeholder(tf.float32, shape=[None, 10])
When I run this in TF 2.x, I get:
AttributeError: module 'tensorflow' has no attribute 'placeholder'
I understand that placeholders are removed in TF 2.x. I want to know the correct way to replace this code using TF 2.x tensors or Keras, keeping the same behavior for training a neural network.
I want to replace placeholders with TensorFlow 2.x style tensors so I can feed batches of data without using deprecated compat.v1 code.
tf.placeholderistf.keras.Input, which explicitly defines your model's entry point, such asinputs = tf.keras.Input(shape=(784,)). You then build a model with the Keras Functional API and pass your data directly tomodel.fit(), which completely replaces the oldfeed_dictand session logic.