【问题标题】:Adding more layers to tensorflow MNIST tutorial makes accuracy drop向 tensorflow MNIST 教程添加更多层会导致精度下降
【发布时间】:2017-06-18 23:58:14
【问题描述】:

深度学习新手。 使用 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。我能知道它为什么会下降吗?

【问题讨论】:

标签: machine-learning tensorflow neural-network deep-learning mnist


【解决方案1】:

我认为您需要symmetry breaking in the weights 和层之间的非线性激活:

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。

【讨论】:

  • 谢谢。它使多层网络比单层网络更好。
【解决方案2】:

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

【讨论】:

  • 使用 random_normal 修复 W、B 初始化修复它,准确度 = 0.89。这仍然低于单层版本。但现在看来,正如您所指出的@Lukasz Tracewski 所指出的,梯度消失问题。谢谢
  • 如果我要猜测,那是因为您的神经网络实际上可以通过调整第二层和后续层来处理随机权重。更糟糕的是,因为它必须处理第一个隐藏层“噪声”,这很难学习“正确”的权重。
【解决方案3】:

您需要在层之间添加一个非线性激活函数。试试 ReLU。

【讨论】:

  • Y1 = tf.nn.relu(tf.matmul(x, W1) + B1) Y2 = tf.nn.relu(tf.matmul(Y1, W2) + B2) Y3 = tf.matmul(Y2, W3) + B3 我试过了,但准确度是 0.1135
  • 尝试绘制损失函数与迭代的关系。损失函数应该会稳步下降。
猜你喜欢
  • 1970-01-01
  • 2017-09-20
  • 1970-01-01
  • 2018-11-05
  • 2017-04-13
  • 2017-08-15
  • 2021-08-17
  • 2016-08-02
  • 1970-01-01
相关资源
最近更新 更多