【问题标题】:Simple tensorflow neural network not increasing accuracy or decreasing loss?简单的张量流神经网络不提高准确性或减少损失?
【发布时间】:2016-08-31 07:02:28
【问题描述】:

我有以下网络进行训练,

graph = tf.Graph()
with graph.as_default():

    tf_train_dataset = tf.constant(X_train)
    tf_train_labels = tf.constant(y_train)
    tf_valid_dataset = tf.constant(X_test)

    weights = tf.Variable(tf.truncated_normal([X_train.shape[1], 1]))

    biases = tf.Variable(tf.zeros([num_labels]))
    logits = tf.nn.softmax(tf.matmul(tf_train_dataset, weights) + biases)

    loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits, tf_train_labels))
    optimizer = tf.train.GradientDescentOptimizer(0.5).minimize(loss)
    train_prediction = tf.nn.softmax(logits)
    valid_prediction = tf.nn.softmax(tf.matmul(tf_valid_dataset, weights) + biases)

我运行它如下,

num_steps = 10

with tf.Session(graph=graph) as session: 
    tf.initialize_all_variables().run()
    print('Initialized')
    for step in range(num_steps):
        _, l, predictions = session.run([optimizer, loss, train_prediction])
        print("Loss: ",l)
        print('Training accuracy: %.1f' % sklearn.metrics.accuracy_score(predictions.flatten(), y_train.flatten()))

但是输出如下

Initialized
Loss:  0.0
Training accuracy: 0.5
Loss:  0.0
Training accuracy: 0.5

X_train 的形状为 (213403, 25),y_train 的形状为 (213403, 1),以应对 logits。我没有将标签编码为一个热点,因为只有两个类,1 或 0。我也尝试了二次损失函数,它仍然是一样的,同样的事情发生了,损失函数没有减少全部。我在这里感觉到语法错误,但我一无所知。

【问题讨论】:

    标签: neural-network tensorflow


    【解决方案1】:

    您将标签作为单列传递(没有编码)。 模型无法将标签作为因子类型。 因此,它将您的标签视为连续值。

    损失:0.0 表示损失为零。这意味着您的模型非常适合。 发生这种情况是因为您的标签是连续的(回归函数)并且您使用的是 softmax_cross_entropy_with_logits 损失函数。

    尝试传递标签的一种热编码并检查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 2018-01-10
      相关资源
      最近更新 更多