2
我有一个TensorFlow模型,其中的一些特点:如何解释TensorFlow预测,他们似乎有错误的形状
state_size = 800,
num_classes = 14313,
batch_size = 10,
num_steps = 16, # width of the tensor
num_layers = 3
x = tf.placeholder(tf.int32, [batch_size, num_steps], name='input_placeholder')
y = tf.placeholder(tf.int32, [batch_size, num_steps], name='labels_placeholder')
rnn_inputs = [tf.squeeze(i, squeeze_dims=[1]) for i in
tf.split(x_one_hot, num_steps, 1)] # still a list of tensors (batch_size, num_classes)
...
logits = tf.matmul(rnn_outputs, W) + b
predictions = tf.nn.softmax(logits)
现在我想给它一个np.array(形状的batch_size = X num_steps,所以10×16),我得到一个预测张量。
奇怪的是,它的形状是160 x 14313.后者是类的数量。但是160从哪里来?我不明白这一点。我希望每个类的概率对于批次中的每个元素(即10个)都是可能的。 num_steps如何卷入,如何从这个pred读取。张量这是16个数字之后的预期元素?
我明白了,谢谢你。 softmax不给我正确的概率吗?我应该使用exp函数?所以我认为我应该只预测一个值而不是16个。为了避免混淆,我在另一个问题中发布了这个问题。 https://stackoverflow.com/questions/42766458/tensorflow-predicting-sequences-what-is-x-and-y – dorien
tf.nn.softmax计算通过softmax层的前向传播。在计算模型输出的概率时,可以在评估模型时使用它。所以是的,它会给你正确的概率,我想提供另一种方式,只是与logits。 – SerialDev
与此相关。我似乎不知道哪个标签与哪个预测值有关。这应该很容易得到正确的? https://stackoverflow.com/questions/43039055/how-to-get-class-labels-from-tensorflow-prediction – dorien