张量流中权重初始化(针对n维输入)

时间:2019-03-25 06:09:24

标签: tensorflow

训练集x_train包含10k个示例,每个输入的形状为(10,23201) 当我尝试发送总训练集进行训练时,出现错误 但是当我一次发送10个示例时,它工作正常。 如何更改将一次使用所有示例的代码(权重的形状将改变我的问题)?

input_features = 23201
hidden_layer_1 = 300
hidden_layer_2 = 300
hidden_layer_3 = 128

limit_1 = tf.cast(np.sqrt(6/(input_features+hidden_layer_1)), tf.float32)
limit_2 = tf.cast(np.sqrt(6/(hidden_layer_1+hidden_layer_2)), tf.float32)
limit_3 = tf.cast(np.sqrt(6/(hidden_layer_2+hidden_layer_3)), tf.float32)
#weights initialization
w0 = tf.Variable(tf.random_uniform([10, input_features, hidden_layer_1], -limit_1, limit_1))
w1 = tf.Variable(tf.random_uniform([10, hidden_layer_1, hidden_layer_2],-limit_2, limit_2))
w2 = tf.Variable(tf.random_uniform([10, hidden_layer_2, hidden_layer_3], -limit_3, limit_3))

#biases initializatrion
b0 = tf.Variable(tf.random_uniform([10, hidden_layer_1], -limit_1, limit_1))
b1 = tf.Variable(tf.random_uniform([10, hidden_layer_2], -limit_2, limit_2))
b2 = tf.Variable(tf.random_uniform([10, hidden_layer_3], -limit_3, limit_3))

q_x = tf.placeholder("float32", shape=[None, 10, input_features])
d_x = tf.placeholder("float32", shape=[None, 10, input_features])
y = tf.placeholder("float32", shape=[None, 10])

0 个答案:

没有答案