在tensorflow2.x版本的tensorflow.contrib.metrics里没有aggregate

在tensorflow2.x版本的tensorflow.contrib.metrics里没有aggregate,第1张

如果使用一行的代码内的tensorflow 2.0中运行

tf.contrib.metrics.aggregate_metric_map()

运行时会出现错误

AttributeError: module 'tensorflow' has no attribute 'contrib'

那么我们如何在tensorflow2.X里访问aggregate_metric_map()呢?可以从旧tensorflow存储库复制该函数放到metrics里,因为它没有任何特殊的依赖关系

def aggregate_metric_map(names_to_tuples):
  """Aggregates the metric names to tuple dictionary.
  This function is useful for pairing metric names with their associated value
  and update ops when the list of metrics is long. For example:
  python
    metrics_to_values, metrics_to_updates = slim.metrics.aggregate_metric_map({
        'Mean Absolute Error': new_slim.metrics.streaming_mean_absolute_error(
            predictions, labels, weights),
        'Mean Relative Error': new_slim.metrics.streaming_mean_relative_error(
            predictions, labels, labels, weights),
        'RMSE Linear': new_slim.metrics.streaming_root_mean_squared_error(
            predictions, labels, weights),
        'RMSE Log': new_slim.metrics.streaming_root_mean_squared_error(
            predictions, labels, weights),
    })

  Args:
    names_to_tuples: a map of metric names to tuples, each of which contain the
      pair of (value_tensor, update_op) from a streaming metric.
  Returns:
    A dictionary from metric names to value ops and a dictionary from metric
    names to update ops.
  """
  metric_names = names_to_tuples.keys()
  value_ops, update_ops = zip(*names_to_tuples.values())
  return dict(zip(metric_names, value_ops)), dict(zip(metric_names, update_ops))

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/570341.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存