init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for step in range(200):
sess.run([train_op],feed_dict={x: x_dat, y: y_dat})
if step % 20 == 0:
print(sess.run([loss,w,b]))
程序如上,报错如下:
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float
[[Node: Variable_1/_17 = _Recv[_start_time=0, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_28_Variable_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
placehoder错误,其中每个使用占位符的操作都需要传入数据,程序修改如下:
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for step in range(200):
sess.run([train_op],feed_dict={x: x_dat, y: y_dat})
if step % 20 == 0:
print(sess.run([loss,w,b],feed_dict={x: x_dat, y: y_dat}))