从[tensorflow 1.00]中的softmax层中提取概率 [英] Extracting probabilities from a softmax layer in [tensorflow 1.00]

查看:324
本文介绍了从[tensorflow 1.00]中的softmax层中提取概率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用张量流,我有一个LSTM分类模型,其中softmax作为最终节点.
这是我的softmax层:

Using tensorflow, I have an LSTM classification model with a softmax as the final node.
This is my softmax layer:

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

我的问题是,当用新颖的数据评估该模型时,如何提取每个类的概率?

My question is when evaluating this model with novel data, how can I extract the probabilities for each class?

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

推荐答案

只需添加行

probs = tf.nn.softmax(logits)

然后做

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

这篇关于从[tensorflow 1.00]中的softmax层中提取概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆