【问题标题】:Extracting probabilities from a softmax layer in [tensorflow 1.00]从 [tensorflow 1.00] 中的 softmax 层提取概率
【发布时间】:2017-03-15 15:53:12
【问题描述】:

使用 tensorflow,我有一个以 softmax 作为最终节点的 LSTM 分类模型。
这是我的 softmax 层:

with tf.name_scope("Softmax") as scope:
            with tf.variable_scope("Softmax_params"):
                softmax_w = tf.get_variable("softmax_w", [hidden_size, num_classes])
                softmax_b = tf.get_variable("softmax_b", [num_classes])
            logits = tf.nn.xw_plus_b(output, softmax_w, softmax_b) # Predicted label, eg y = tf.matmul(X, W) + b)

            loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=self.labels,
                                                                  logits=logits,
                                                                  name='softmax')

我的问题是,在使用新数据评估此模型时,如何提取每个类别的概率?

num_class = 129

for i in range(runs):
    X_batch, y_batch = sample_batch(X_test[:200], y_test[:200], batch_size)
    predictions = sess.run([model.logits], feed_dict = {model.input: X_batch, model.keep_prob: 1.0})

【问题讨论】:

  • 预测变量有什么问题?
  • 没有错,我只是想知道是否有最理想的方法来获取每个类的概率。

标签: python tensorflow neural-network


【解决方案1】:

只需添加一行

probs = tf.nn.softmax(logits)

那就做吧

predictions = sess.run(model.probs, feed_dict=feed_dict)

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 2020-06-10
    • 2018-10-28
    • 1970-01-01
    相关资源
    最近更新 更多