I'm trying to convert a simple snippet from TensorFlow 1.x to TensorFlow 2:
# ########## TensorFlow 1.x code: ##########
import numpy as np
import tensorflow as tf
coefficients = np.array([[1.], [-10.], [25.]])
w = tf.Variable(0, dtype=tf.float32)
x = tf.placeholder(tf.float32, [3, 1])
cost = (x[0][0] * (w**2)) + (x[1][0]*w) + (x[2][0])
train = tf.train.GradientDescentOptimizer(0.05).minimize(cost)
if __name__ == '__main__':
init = tf.global_variables_initializer()
session = tf.Session()
session.run(init)
for i in range(100):
session.run(train, feed_dict={x: coefficients})
print(session.run(w))
Much of the old API has been replaced in TF2 (e.g. GradientDescentOptimizer replaced with keras.optimizers.SGD), and I was able to figure out how to refactor most of my code, but I don't know how to refactor tf.placeholder and feed_dict and how those two interact. Is the use of placeholders simply eschewed in TF2?