Keras model.evaluate()和model.predict()有什么区别? [英] What is the difference between Keras model.evaluate() and model.predict()?

查看:384
本文介绍了Keras model.evaluate()和model.predict()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Keras生物医学图像分割技术来分割大脑神经元.我使用model.evaluate()它给了我骰子系数:0.916.但是,当我使用model.predict()时,然后通过计算Dice系数遍历预测图像,Dice系数为0.82.为什么这两个值不同?

解决方案

问题在于,Keras中的每个指标都是以以下方式评估的:

  1. 对于每个batch,都会评估一个指标值.
  2. 当前的损失值(在k个批次之后等于计算的k个批次中指标的平均值).
  3. 获得的最终结果是所有批次计算出的所有损失的平均值.

大多数最受欢迎的度量标准(例如msecategorical_crossentropymae)等-作为每个示例的损失值的平均值-具有这样的属性,即这样的评估最终会得出正确的结果.但是,在骰子系数的情况下-所有批次中其值的平均值不等于在整个数据集上计算出的实际值,并且model.evaluate()使用这种计算方式-这就是问题的直接原因.

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?

解决方案

The problem lies in the fact that every metric in Keras is evaluated in a following manner:

  1. For each batch a metric value is evaluated.
  2. A current value of loss (after k batches is equal to a mean value of your metric across computed k batches).
  3. The final result is obtained as a mean of all losses computed for all batches.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆