Deep learning tf.keras.metrics.MeanIoU给出的结果与等式不同

Deep learning tf.keras.metrics.MeanIoU给出的结果与等式不同,deep-learning,keras-metrics,Deep Learning,Keras Metrics,我在我的模型中使用了tf.keras.metrics.MeanIoU(我只有两个类),但它给出的结果与我应用等式IOU=true\u-positive/(true\u-positive+false\u-positive+false\u-negative)时不同。(我通过使用tf.keras.metrics.TruePositives(),tf.keras.FalsePositives(),tf.keras.metrics.FalsePositives(),tf.keras.metrics.Fal

我在我的模型中使用了
tf.keras.metrics.MeanIoU
(我只有两个类),但它给出的结果与我应用等式
IOU=true\u-positive/(true\u-positive+false\u-positive+false\u-negative)时不同。
(我通过使用
tf.keras.metrics.TruePositives()
tf.keras.FalsePositives(),
tf.keras.metrics.FalsePositives()
tf.keras.metrics.FalseNegatives(),
tf.keras.metrics.FalseNegatives()
tf.keras.metrics.TrueNegatives()。
我使用模型的所有指标。compile()

以下是
模型的结果。评估(X\u有效,y\u有效,verbose=1)

如果我应用上面提到的等式,
IoU
应该是0.427

我对F1分数也有类似的问题,所以我决定通过调用一个自定义函数来计算它,该函数使用
tf.keras.metrics.Precision()
tf.keras.metrics.Recall()

这里有什么问题

后续问题:样本重量在
tf.keras.metrics.MeanIoU
中如何工作?我如何理解以下示例:

True: [0, 0, 1, 1]
Pred: [0, 1, 0, 1]
-->TP=1,FP=1,FN=1-->IoU=1/(1+1+1)=0.3334;样本权重=0.3,0.3,0.1]IoU=(1x0.1)/(1x0.1+1x0.3+1x0.3)=0.143

有人能澄清一下吗

谢谢

True: [0, 0, 1, 1]
Pred: [0, 1, 0, 1]