Keras model.evaluate() 和 model.predict() 有什么区别? [英] What is the difference between Keras model.evaluate() and model.predict()?
问题描述
我使用 Keras 生物医学图像分割来分割大脑神经元.我使用了 model.evaluate()
它给了我骰子系数:0.916.但是,当我使用 model.predict()
时,然后通过计算 Dice 系数循环预测图像,Dice 系数为 0.82.为什么这两个值不同?
I used Keras biomedical image segmentation to segment brain neurons. I used model.evaluate()
it gave me Dice coefficient: 0.916. However, when I used model.predict()
, then loop through the predicted images by calculating the Dice coefficient, the Dice coefficient is 0.82. Why are these two values different?
推荐答案
问题在于 Keras
中的每个指标都以下列方式进行评估:
The problem lies in the fact that every metric in Keras
is evaluated in a following manner:
- 对于每个
batch
,都会评估一个指标值. - 损失的当前值(在
k
个批次之后等于计算的k
个批次的指标的平均值). - 最终结果是为所有批次计算的所有损失的平均值.
- For each
batch
a metric value is evaluated. - A current value of loss (after
k
batches is equal to a mean value of your metric across computedk
batches). - The final result is obtained as a mean of all losses computed for all batches.
大多数最流行的指标(如 mse
、categorical_crossentropy
、mae
)等 - 作为每个示例的损失值的平均值- 具有这样的评估最终会得到正确结果的属性.但是在骰子系数的情况下 - 所有批次的平均值不等于在整个数据集上计算的实际值,并且 model.evaluate()
使用这种计算方式 - 这是问题的直接原因.
Most of the most popular metrics (like mse
, categorical_crossentropy
, mae
) etc. - as a mean of loss value of each example - have a property that such evaluation ends up with a proper result. But in case of Dice Coefficient - a mean of its value across all of the batches is not equal to actual value computed on a whole dataset and as model.evaluate()
uses such way of computations - this is the direct cause of your problem.
这篇关于Keras model.evaluate() 和 model.predict() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!