Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
两层神经网络Tensorflow python_Python_Tensorflow_Neural Network - Fatal编程技术网

两层神经网络Tensorflow python

两层神经网络Tensorflow python,python,tensorflow,neural-network,Python,Tensorflow,Neural Network,嗨,我是tensorflow和神经网络的新手。我试图实现一个两层神经网络用于数字识别。当只有一层时,代码运行良好,但在添加第二层后,精度下降到0.11xxxx。我的代码怎么了?提前感谢您可以使用随机法初始化权重 #layer 1 w1 = tf.Variable(tf.zeros([784, 30])) b1 = tf.Variable(tf.zeros([30])) y1 = tf.nn.relu(tf.matmul(X, w1) + b1) #layer 2 w2 = tf.Variabl

嗨,我是tensorflow和神经网络的新手。我试图实现一个两层神经网络用于数字识别。当只有一层时,代码运行良好,但在添加第二层后,精度下降到0.11xxxx。我的代码怎么了?提前感谢

您可以使用随机法初始化权重

#layer 1
w1 = tf.Variable(tf.zeros([784, 30]))
b1 = tf.Variable(tf.zeros([30]))
y1 = tf.nn.relu(tf.matmul(X, w1) + b1)

#layer 2
w2 = tf.Variable(tf.zeros([30, 10]))
b2 = tf.Variable(tf.zeros([10]))
logits = tf.matmul(y1, w2) + b2
preds = tf.nn.softmax(logits)

嗨,谢谢你的建议。它现在可以工作了,但开始时只有0.43,20个历元后达到0.907,这还不错,但我想知道为什么它比1层还要差,这对我来说没有意义。我还意识到第一次训练损失非常高(11.8),也许这就是为什么它从0.43开始的原因。我用它来计算损失:batch_xentropy=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=Y,logits=logits))我找到了解决方案,用截断法初始化修复了问题。谢谢你给我指明了正确的方向。
w1 = tf.Variable(tf.random_normal([784, 30]))
...
w2 = tf.Variable(tf.random_normal([30, 10]))