在 tensorflow MNIST 教程中添加更多层会导致精度下降

Adding more layers to tensorflow MNIST tutorial makes accuracy drop

深度学习新手。 使用来自 gogoel tensorflow ( https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/mnist/mnist_softmax.py) 的 MNIST_SOFTMAX.py 教程,我添加了两个新层只是为了看看会发生什么。

x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.matmul(x, W) + b

将上面的代码更改为

x = tf.placeholder(tf.float32, [None, 784])
W1 = tf.Variable(tf.zeros([784, 256]))
W2 = tf.Variable(tf.zeros([256, 256]))
W3 = tf.Variable(tf.zeros([256, 10]))

B1 = tf.Variable(tf.zeros([256]))
B2 = tf.Variable(tf.zeros([256]))
B3 = tf.Variable(tf.zeros([10]))

Y1 = tf.matmul(x, W1) + B1
Y2 = tf.matmul(Y1, W2) + B2
Y3 = tf.matmul(Y2, W3) + B3
y = Y3

它将精度从 0.9188 降低到 0.1028。我能知道为什么它会下降吗?

您需要在层之间添加一个 non-linear 激活函数。试试 ReLU。

您遇到的问题与 中回答的问题相同。本质上,你的第一个隐藏层比最后一个学习得慢得多。通常你的网络应该学习正确的权重。然而,在这里,很可能第一层中的权重变化很小,错误会传播到下一层。它太大了,以至于后续层都无法纠正它。检查权重。

我认为你需要 symmetry breaking in the weights 和层之间的 non-linear 激活:

W = tf.Variable(tf.random_normal([784, 256], stddev=0.1)) 
W1 = tf.Variable(tf.random_normal([256, 256], stddev=0.1))
W2 = tf.Variable(tf.random_normal([256, 10], stddev=0.1))
b = tf.Variable(tf.zeros([256]))
b1 = tf.Variable(tf.zeros([256]))
b2 = tf.Variable(tf.zeros([10]))

y = tf.matmul(x, W) + b
y = tf.nn.relu(y)
y = tf.matmul(y, W1) + b1
y = tf.nn.relu(y)
y = tf.matmul(y, W2) + b2

得到 0.9653 的准确度。