我有一个问题,那里有图像和给定的问题。答案的格式为[False,True]
。在训练期间,我尝试找出预测是对还是错。
def build_loss(logits,labels):
# Cross-entropy loss
loss = tf.nn.sigmoid_cross_entropy_with_logits(logits=logits,labels=labels)
# Classification accuracy
correct_prediction = tf.equal(tf.argmax(logits,1),tf.argmax(labels,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
return tf.reduce_mean(loss),accuracy
logits = C(self.img,self.q,scope='Classifier')
self.all_preds = tf.nn.softmax(logits)
self.loss,self.accuracy = build_loss(logits,self.a)
假设原始答案为[0,0]
,预测答案为[0,1]
,则logit和label的tf.argmax
都将返回值1。有没有办法避免这种情况比较难看?我尝试将tf.argmax
替换为tf.reduce_max
,但准确性始终为0。
或者还有其他方法可以更改模型,因此,与其在输出层中拥有2个神经元,不如在1个神经元中完成它。目前,我正在使用tf.nn.softmax
来找到预测,tf.nn.sigmoid_cross_entropy_with_logits
是我的损失函数。