为什么我们需要 tf.arg_max(Y,1) with softmax in tensorflow?
why we need tf.arg_max(Y,1) with softmax in tensorflow?
写tensorflow demo的时候,在correct_predition
的定义中发现了这个arg_max()
函数
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(
logits=hypothesis,labels=Y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
correct_prediction = tf.equal(tf.arg_max(hypothesis,1),tf.arg_max(Y,1))
Returns张量跨轴最大值的索引。(这是来自TF的API)
因为我们使用'softmax_cross_entropy_with_logits
',
预测(hypothesis
)表示为概率
我们将通过arg_max()
函数得到最大预测概率的索引hypothesis
但是Y
是标签,不是我们需要使用的概率tf.arg_max(Y,1)
?
arg_max(假设)是 returning 一个索引。
Y 是一个长度为 10 的单热向量。
tf.equal() 在这里不能做任何明智的事情,因为这两件事不兼容。
因此,arg_max(Y) return 是一个索引。
现在 tf.equal() 可以做一件明智的事情:如果预测与目标匹配则为 1,否则为 0。
请注意 arg_max() 不是概率函数:它只是 return 最大元素索引的函数。
写tensorflow demo的时候,在correct_predition
的定义中发现了这个arg_max()
函数
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(
logits=hypothesis,labels=Y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
correct_prediction = tf.equal(tf.arg_max(hypothesis,1),tf.arg_max(Y,1))
Returns张量跨轴最大值的索引。(这是来自TF的API)
因为我们使用'softmax_cross_entropy_with_logits
',
预测(hypothesis
)表示为概率
我们将通过arg_max()
函数得到最大预测概率的索引hypothesis
但是Y
是标签,不是我们需要使用的概率tf.arg_max(Y,1)
?
arg_max(假设)是 returning 一个索引。 Y 是一个长度为 10 的单热向量。 tf.equal() 在这里不能做任何明智的事情,因为这两件事不兼容。
因此,arg_max(Y) return 是一个索引。 现在 tf.equal() 可以做一件明智的事情:如果预测与目标匹配则为 1,否则为 0。
请注意 arg_max() 不是概率函数:它只是 return 最大元素索引的函数。