aymericdamien / TensorFlow-Examples

TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In the tf1 example: I replace the weigtht and bias with tf.layers.dense, I found the accuracy decrease. why???

SmileGoat opened this issue · comments

def RNN(x, weights, biases):

# Prepare data shape to match `rnn` function requirements
# Current data input shape: (batch_size, timesteps, n_input)
# Required shape: 'timesteps' tensors list of shape (batch_size, n_input)

# Unstack to get a list of 'timesteps' tensors of shape (batch_size, n_input)
x = tf.unstack(x, timesteps, 1)

# Define a lstm cell with tensorflow
lstm_cell = rnn.BasicLSTMCell(num_hidden, forget_bias=1.0)

# Get lstm cell output
outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)

return tf.layers.dense(outputs[-1], num_classes, activation=None, kernel_regularizer=tf.contrib.layers.l2_regularizer(1e-2)) 
#return tf.matmul(outputs[-1], weights['out']) + biases['out']

use dense: the acc is 0.507
but use tf.matmul(outputs[-1], weights['out']) + biases['out']) is 0.906

in fact, use dense, the model need to train more than 30000 iterations , and then it will reach the acc to 0.90 + .