首页 文章

向tensorflow添加更多层MNIST教程使精度下降

提问于
浏览
1

新手要深入学习 . 通过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 . 我可以知道它为什么会下降 .

3 回答

  • 2

    我认为你需要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 .

  • 1

    您遇到与this post中回答的问题相同的问题 . 从本质上讲,你的第一个隐藏层比上一个学习慢得多 . 通常,您的网络应该学习正确的权重 . 然而,这里,第一层中的权重很可能变化很小,并且误差传播到下一层 . 它's so large that the subsequent layers can' t可能是正确的 . 检查重量 .

  • 3

    您需要在图层之间添加非线性激活功能 . 试试ReLU .

相关问题