tensorflow 学习纪录(持续更新)

 1 import tensorflow as tf
 2 import numpy as np
 3 
 4 #tensor = tf.constant([[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8]])
 5 tensor = tf.placeholder(tf.int32, [2,8])
 6 
 7 with tf.Session() as sess:
 8     sess.run(tf.global_variables_initializer())
 9     print sess.run(tensor,feed_dict={tensor:[[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8]]})
10     print sess.run(tensor)
11     tensorReshape = tf.reshape(tensor,[-1,4])
12     print sess.run(tensorReshape)

print sess.run(tensor) 会报错,

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype int32 and shape [2,8]
[[Node: Placeholder = Placeholder[dtype=DT_INT32, shape=[2,8], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

原因:feed 使用一个 tensor 值临时替换一个操作的输出结果. 你可以提供 feed 数据作为 run() 调用的参数. feed 只在调用它的方法内有效, 方法结束, feed 就会消失。

猜你喜欢

转载自www.cnblogs.com/tsw123/p/9190824.html