Beginner and trying to use tensorboard in my tensorflow prgm. I added tensorboard refs as I saw in the tutorials, but I get the error message below :
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'x' with dtype float [[Node: x = Placeholderdtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]]
Error seems related to this line I added in my training loop. Without this line the program throws no errors:
summary = sess.run(merged_summary_op, {x: x_train, y_prim: y_train})
Thanks if somebody can check my code below and help:
# -*- coding: utf-8 -*-
import tensorflow as tf
sess = tf.Session()
# parms
a = tf.Variable([2.0], dtype=tf.float32, name="a")
x = tf.placeholder(tf.float32, name="x")
b = tf.Variable([1.0], dtype=tf.float32, name="b")
# model : y=ax+b
with tf.name_scope('Model'):
y = tf.add ((tf.multiply(a, x)), b)
# info for TensorBoard
writer = tf.summary.FileWriter("D:\\tmp\\tensorflow\\logs", sess.graph)
# loss fct - mean square error
with tf.name_scope('cost'):
y_prim = tf.placeholder(tf.float32)
cost = tf.reduce_sum(tf.square(y - y_prim))
# optimizer = gradientdescent
with tf.name_scope('GradDes'):
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(cost)
# train datas
x_train = [1, 2, 3, 4]
y_train = [5.2, 8.4, 11.1, 14.7]
# summary for Tensorboard
tf.summary.scalar("cost", cost)
merged_summary_op = tf.summary.merge_all()
# init vars
init = tf.global_variables_initializer()
# train loop
sess.run(init)
for i in range (500):
sess.run([train, cost], feed_dict={x: x_train, y_prim: y_train})
summary = sess.run(merged_summary_op, {x: x_train, y_prim: y_train})
a_found, b_found, curr_cost = sess.run([a, b, cost], feed_dict={x:x_train, y_prim: y_train})
print("iteration :", i, "a: ", a_found, "b: ", b_found, "cost: ",curr_cost)