我正在建立一个图形,我希望初始权重有可变的标准差。我试图使用以下命令,但它产生了一个错误:
import tensorflow as tf
import numpy as np
stddev = tf.placeholder(dtype=tf.float32)
a = tf.placeholder(dtype=tf.float32, shape=[1,50])
weight1 = tf.Variable(tf.truncated_normal(shape=[50, 30],stddev=stddev))
result = tf.reduce_sum(tf.matmul(a, weight1))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(result , {a: np.random.randn(1, 50), stddev: 0.01}))有人能帮我解决这个问题吗?我知道我可以在定义stddev时设置它,但我面临的任务是在培训过程中使用一个变体stddev。
发布于 2017-11-08 12:25:57
像这样使用tf.placeholder_with_default:
import numpy as np
import tensorflow as tf
stddev = tf.placeholder_with_default(0.1, shape=(), name='stddev')
weight1 = tf.Variable(tf.truncated_normal(shape=[50, 30], stddev=stddev))
a = tf.placeholder(dtype=tf.float32, shape=[1,50])
result = tf.reduce_sum(tf.matmul(a, weight1))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(result , feed_dict={a: np.random.randn(1, 50), stddev: 0.01}))https://stackoverflow.com/questions/47179545
复制相似问题