python-2.7 - 如何手动初始化权重值?

标签 python-2.7 neural-network tensorflow

我想尝试一下 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/

相关文章:

python - Pandas 读取带空白的多索引 csv

python - 从 GAE 数据存储区删除数据时出现错误 : AttributeError: 'list' object has no attribute 'fetch'

machine-learning - 激活函数之前对数据进行归一化

python - 使用指标 'acc' 和 tf.keras.metrics.Accuracy() 有什么区别

python - 为 TensorFlow reshape Gym 数组

python - 在Python中不使用默认输出(播放)设备播放mp3文件

python - 从 Salesforce 访问公司数据

c++ - 线程数不同,答案不同

tensorflow - 输出中的节点数大于神经网络中的类数

random - 使用 tf.random 多次运行 session 会返回不同的 conv2d 值