【发布时间】:2018-03-14 06:02:26
【问题描述】:
有一个函数tf.get_variable('name') 允许“隐式”将参数传递给函数,例如:
def function(sess, feed):
with tf.variable_scope('training', reuse=True):
cost = tf.get_variable('cost')
value = sess.run(cost, feed_dict=feed)
# other statements
但是如果想将tf.placeholder 传递给函数怎么办?占位符是否有相同的机制,例如tf.get_placeholder():
def function(sess, cost, X_train, y_train):
# Note this is NOT a valid TF code
with tf.variable_scope('training', reuse=True):
features = tf.get_placeholder('features')
labels = tf.get_placeholder('labels')
feed = {features: X_train, labels: y_train}
value = sess.run(cost, feed_dict=feed)
print('Cost: %s' % value)
或者在函数内部构造占位符并没有太大意义?
【问题讨论】:
标签: python tensorflow