【问题标题】:Keras metrics with TF backend vs tensorflow metrics带有 TF 后端的 Keras 指标与张量流指标
【发布时间】:2018-08-07 20:31:12
【问题描述】:

当 Keras 2.x 删除某些指标时,变更日志表示这样做是因为它们是“基于批处理的”,因此并不总是准确的。这是什么意思? tensorflow 中包含的相应指标是否存在相同的缺点?例如:精度和召回指标。

【问题讨论】:

  • 您能否链接到您询问的变更日志部分?
  • 我的错误,我记错了更新日志。更改日志只是说它们已被弃用并因此被删除,其他地方(例如这里:github.com/keras-team/keras/issues/5794)指的是它们是全局属性近似批处理的事实,这就是它们被删除的原因。这是什么意思?
  • 可能与这个问题有关:github.com/tensorflow/tensorflow/issues/36250 ?

标签: python python-2.7 tensorflow keras keras-2


【解决方案1】:

我们以精度为例。 stateless version which was removed 是这样实现的:

def precision(y_true, y_pred):  
    """Precision metric.    
     Only computes a batch-wise average of precision.   
     Computes the precision, a metric for multi-label classification of 
    how many selected items are relevant.   
    """ 
    true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))  
    predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))  
    precision = true_positives / (predicted_positives + K.epsilon())    
    return precision

如果y_true 包含数据集中的所有标签并且y_pred 具有与所有这些标签相对应的模型预测,这很好。

问题在于人们经常将他们的数据集分成批次,例如通过对 1000 张图像运行 10 次评估来评估 10000 张图像。这可能是适应内存限制所必需的。在这种情况下,您将获得 10 个不同的精度分数,而无法将它们组合起来。

有状态度量通过将中间值保留在变量中并持续整个评估来解决这个问题。因此,在precision 的情况下,有状态度量可能具有true_positivespredicted_positives 的持久计数器。 TensorFlow 指标是有状态的,例如tf.metrics.precision.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2020-03-28
    相关资源
    最近更新 更多