AttributeError: модуль tenensflow не имеет атрибута contrib в тензорном потоке 2.0 - PullRequest
1 голос
/ 03 мая 2020

Я пытаюсь запустить IOS в TenorFlow 2.0 внутри кода, который я использую строку

tf.contrib.metrics.aggregate_metric_map()

, но во время выполнения кода я получаю ошибку как

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

Как мы можем получить доступ к aggregate_metric_map() в TF 2.0?

Ответы [ 2 ]

1 голос
/ 03 мая 2020

Вы можете просто скопировать функцию из старого tensorflow хранилища, так как она не имеет никакой специальной зависимости.

ref: https://github.com/tensorflow/tensorflow/blob/r1.8/tensorflow/contrib/metrics/python/ops/metric_ops.py

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))
0 голосов
/ 03 мая 2020

Tensorflow 2.0 не имеет модуля contrib. Вот цитата из документации TF

Большое количество старого кода TensorFlow 1.x использует библиотеку Slim, которая была упакована с TensorFlow 1.x как tf.contrib.layers. Как модуль вклада, он больше не доступен в TensorFlow 2.0 , даже в tf.compat.v1. Преобразование кода с использованием Slim в TF 2.0 более сложное, чем преобразование репозиториев, использующих v1.layers. На самом деле, имеет смысл сначала преобразовать код Slim в v1.layers, а затем преобразовать в Keras.

Подробнее см. В руководстве по миграции TF

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...