简体   繁体   中英

Two Layer Neural network Tensorflow python

#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)

Hi I'm new to tensorflow and neural network. I tried to implement a two-layer neural network for digit recognition. The code works fine when there is only one layer but after I add the second layer the accuracy dropped to 0.11xxxx. What's wrong with my code? Thanks in advance

You may initialize the weights using random_normal.

w1 = tf.Variable(tf.random_normal([784, 30]))
...
w2 = tf.Variable(tf.random_normal([30, 10]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM