这里总结几种权重矩阵的初始化方式:

1:截断的正态分布:

def init_matrix(shape):
    return tf.truncated_normal(shape, mean=0, stddev=0.1)

2.xavier_initializer()法:这个初始化器是用来保持每一层的梯度大小都差不多相同

tensorflow
一个面向所有人的开源机器学习框架
W = tf.get_variable("W", shape=[784, 100],
                initializer=tf.contrib.layers.xavier_initializer())

3.cs231n推荐:

w=np.random.randn(in,out)/np.sqrt(2.0/in)#in,out为输入输出的神经元个数

使用:
W1_init = np.random.randn(784, 100).astype(np.float32) * np.sqrt(2.0/(784))
b1_init = np.zeros([100]).astype(np.float32)
W2_init = np.random.randn(100, 100).astype(np.float32) * np.sqrt(2.0/(100))
b2_init = np.zeros([100]).astype(np.float32)
W3_init = np.random.randn(100, 10).astype(np.float32) * np.sqrt(2.0/(100))
b3_init = np.zeros([10]).astype(np.float32)
W_inits = [W1_init, b1_init, W2_init, b2_init, W3_init, b3_init]
推荐内容
GitHub 加速计划 / te / tensorflow
25
4
下载
一个面向所有人的开源机器学习框架
最近提交(Master分支:2 个月前 )
4f64a3d5 Instead, check for this case in `ResolveUsers` and `ResolveOperand`, by querying whether the `fused_expression_root` is part of the `HloFusionAdaptor`. This prevents us from stepping into nested fusions. PiperOrigin-RevId: 724311958 2 个月前
aa7e952e Fix a bug in handling negative strides, and add a test case that exposes it. We can have negative strides that are not just -1, e.g. with a combining reshape. PiperOrigin-RevId: 724293790 2 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐