我想尝试一下 Karpathy 在他的讲义中推荐的权重初始化,
the recommended heuristic is to initialize each neuron's weight vector as: w = np.random.randn(n) / sqrt(n), where n is the number of its inputs
来源:http://cs231n.github.io/neural-networks-2/#init
我是Python初学者,我不知道如何实现这个:/
weights = tf.Variable(??)
请帮忙? ...
最佳答案
对于单个值,请使用:
weights = tf.Variable(10)
对于具有随机值的向量:
shape = [784, 625]
weights = tf.Variable(tf.random_normal(shape, stddev=0.01)/tf.sqrt(n))
请注意,您需要 sess.run 来评估变量。
另外,请查看其他随机张量:https://www.tensorflow.org/versions/r0.8/api_docs/python/constant_op.html#random-tensors
关于python-2.7 - 如何手动初始化权重值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36621741/