将张量与二进制值进行比较时出现问题

我有一个问题,那里有图像和给定的问题。答案的格式为[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是我的损失函数。

iCMS 回答:将张量与二进制值进行比较时出现问题

是的,您只能在最后使用一个神经元,并在其中使用乙状结肠激活。

model.add(Dense(1,activation='sigmoid'))
本文链接:https://www.f2er.com/2232265.html

大家都在问