我是机器学习的初学者。我正在尝试训练一个2层完全连接的神经网络。但是在我完成训练之后,重量和偏差几乎与训练前相同。我用随机数字填写它们。
我还注意到我的成本函数每次都返回相同的值。
def neural_network_model(data,weights):
tenz = tf.placeholder('float',[1,31])
var = tf.Variable(tf.ones([1]))
hidden_1_layer = {
"weights":tf.Variable(tf.random_normal([counter,max_len])),
"biases":tf.Variable(tf.random_normal([max_len,max_len]))
}
#hidden_1_layer['weights'] = weights
output_layer = {
"weights":tf.Variable(tf.random_normal([31,2])),
"biases":tf.Variable(tf.random_normal([2]))
}
l1 = tf.add(tf.matmul(data,hidden_1_layer['weights']) , hidden_1_layer['biases'])
tenz = tf.transpose(tf.expand_dims(tf.diag_part(l1),1))
l2 = tf.add(tf.matmul(tenz,output_layer['weights']),output_layer['biases'])
output = tf.nn.relu(l2)
weights = tf.sub(weights,hidden_1_layer['weights'])
return output,weights
prediction,weights = neural_network_model(x,weights)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction,y))
optimizer = tf.train.AdamOptimizer(learning_rate=0.1).minimize(cost)