最近在学习TensorFlow的时候遇到了许多问题,现一一记录,帮助自己记忆的同时也希望能帮到大家。
正文-------------------------------------------------
做分类任务的时候,经常会使用交叉熵函数作为loss来计算:形式如下
def evaluation(logits, labels): with tf.variable_scope('accuracy') as scope:
correct_prediction = tf.equal(tf.argmax(labels, 1), tf.argmax(logits, 1))
correct = tf.cast(correct_prediction, tf.float32) accuracy =
tf.reduce_mean(correct) return accuracy
但是,如果这样写的话,他会报错,如标题那样,说是axis希望在[-1, 1)之间,而不是1,,,,,,,,,,,
这个东西我查了一下,意思是说,axis必须是-1到1之间,并且左闭右开,取值为1是不行的,
于是 将上面代码中的 1改成-1,就可以了!
如下。。。。。。。。。
correct_prediction = tf.equal(tf.argmax(labels, -1), tf.argmax(logits, -1))
热门工具 换一换