当使用tf-tutorials运行时发生了:AttributeError:模块'tensorflow.python.estimator.api.estimator'没有属性'SessionRunHook'

时间:2019-04-02 08:34:58

标签: python tensorflow-estimator

当它在google.colab中正常运行时,我经常阅读有关estorator的tensorflow官方教程。

我使用的环境是win10-64bit&tensorflow-gpu == 1.12.0&python == 3.6.6。

import tensorflow as tf
import tensorflow.feature_column as fc
import os
import sys
import matplotlib.pyplot as plt
from IPython.display import clear_output
tf.enable_eager_execution()

models_path = os.path.join(os.getcwd(), 'models')
sys.path.append(models_path)

from official.wide_deep import census_dataset
from official.wide_deep import census_main

这是错误信息:

D:\python\python.exe F:/hupnos/PycharmProject/estimator/linear_model.py
Traceback (most recent call last):
  File "F:/hupnos/PycharmProject/estimator/linear_model.py", line 13, in <module>
    from official.wide_deep import census_dataset
  File "F:\hupnos\PycharmProject\estimator\models\official\wide_deep\census_dataset.py", line 31, in <module>
    from official.utils.flags import core as flags_core
  File "F:\hupnos\PycharmProject\estimator\models\official\utils\flags\core.py", line 30, in <module>
    from official.utils.flags import _base
  File "F:\hupnos\PycharmProject\estimator\models\official\utils\flags\_base.py", line 25, in <module>
    from official.utils.logs import hooks_helper
  File "F:\hupnos\PycharmProject\estimator\models\official\utils\logs\hooks_helper.py", line 29, in <module>
    from official.utils.logs import hooks
  File "F:\hupnos\PycharmProject\estimator\models\official\utils\logs\hooks.py", line 28, in <module>
    class ExamplesPerSecondHook(tf.estimator.SessionRunHook):
AttributeError: module 'tensorflow.python.estimator.api.estimator' has no attribute 'SessionRunHook'

1 个答案:

答案 0 :(得分:0)

我在tf 1.12上得到了相同的结果。 1.13 API文档确实包含SessionRunHook

in <module>
    class ExamplesPerSecondHook(tf.estimator.SessionRunHook):
AttributeError: module 'tensorflow.python.estimator.api.estimator' has no attribute 'SessionRunHook'
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print(tf.__version__)
1.12.0
>>>