在feed_dict中使用字符串作为key

tensorflow中这个样子是可以的:(注意最后一行的feed_dict)

import tensorflow as tf
inp = tf.placeholder(tf.int32, shape=[None, None], name='input')
sess=tf.Session()
sess.run(x,feed_dict={'input:0': [1,2,3,4]})

不完善的文档里是这么写的:
在这里插入图片描述
key可以是

  1. tf.Tensor或者tf.placeholder
  2. tf.SparseTensor
  3. a tuple

没有说key还可以是字符串,在tensor名后面加":0"就可以

相关阅读:
Why not feed placeholders by name?
How to understand the term tensor in TensorFlow?

猜你喜欢

转载自blog.csdn.net/sinat_24070543/article/details/83110260