尝试导入tensorflow_hub时出现此错误:无法从'tensorflow.python.distribute'导入名称'parameter_server_strategy_v2'
我运行了这个代码:
import tensorflow_hub as hub
我收到此错误:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-5c017171c13e> in <module>
----> 1 import tensorflow_hub as hub
~anaconda3envsPython 3-7libsite-packagestensorflow_hub__init__.py in <module>
86
87
---> 88 from tensorflow_hub.estimator import LatestModuleExporter
89 from tensorflow_hub.estimator import register_module_for_export
90 from tensorflow_hub.feature_column import image_embedding_column
~anaconda3envsPython 3-7libsite-packagestensorflow_hubestimator.py in <module>
60
61
---> 62 class LatestModuleExporter(tf.compat.v1.estimator.Exporter):
63 """Regularly exports registered modules into timestamped directories.
64
~AppDataRoamingPythonPython37site-packagestensorflowpythonutillazy_loader.py in __getattr__(self, item)
60
61 def __getattr__(self, item):
---> 62 module = self._load()
63 return getattr(module, item)
64
~AppDataRoamingPythonPython37site-packagestensorflowpythonutillazy_loader.py in _load(self)
43 """Load the module and insert it into the parent's globals."""
44 # Import the target module and insert it into the parent's namespace
---> 45 module = importlib.import_module(self.__name__)
46 self._parent_module_globals[self._local_name] = module
47
~anaconda3envsPython 3-7libimportlib__init__.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
~AppDataRoamingPythonPython37site-packagestensorflow_estimatorpythonestimatorapi__init__.py in <module>
8 import sys as _sys
9
---> 10 from tensorflow_estimator.python.estimator.api._v1 import estimator
11
12 del _print_function
~AppDataRoamingPythonPython37site-packagestensorflow_estimatorpythonestimatorapi_v1estimator__init__.py in <module>
8 import sys as _sys
9
---> 10 from tensorflow_estimator.python.estimator.api._v1.estimator import experimental
11 from tensorflow_estimator.python.estimator.api._v1.estimator import export
12 from tensorflow_estimator.python.estimator.api._v1.estimator import inputs
~AppDataRoamingPythonPython37site-packagestensorflow_estimatorpythonestimatorapi_v1estimatorexperimental__init__.py in <module>
8 import sys as _sys
9
---> 10 from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
11 from tensorflow_estimator.python.estimator.canned.kmeans import KMeansClustering as KMeans
12 from tensorflow_estimator.python.estimator.canned.linear import LinearSDCA
~AppDataRoamingPythonPython37site-packagestensorflow_estimatorpythonestimatorcanneddnn.py in <module>
29 from tensorflow.python.keras.utils import losses_utils
30 from tensorflow.python.util.tf_export import estimator_export
---> 31 from tensorflow_estimator.python.estimator import estimator
32 from tensorflow_estimator.python.estimator.canned import head as head_lib
33 from tensorflow_estimator.python.estimator.canned import optimizers
~AppDataRoamingPythonPython37site-packagestensorflow_estimatorpythonestimatorestimator.py in <module>
50 from tensorflow.python.util.tf_export import estimator_export
51 from tensorflow_estimator.python.estimator import model_fn as model_fn_lib
---> 52 from tensorflow_estimator.python.estimator import run_config
53 from tensorflow_estimator.python.estimator import util as estimator_util
54 from tensorflow_estimator.python.estimator.export import export_lib
~AppDataRoamingPythonPython37site-packagestensorflow_estimatorpythonestimatorrun_config.py in <module>
28 from tensorflow.core.protobuf import rewriter_config_pb2
29 from tensorflow.python.distribute import estimator_training as distribute_coordinator_training
---> 30 from tensorflow.python.distribute import parameter_server_strategy_v2
31 from tensorflow.python.util import compat_internal
32 from tensorflow.python.util import function_utils
ImportError: cannot import name 'parameter_server_strategy_v2' from 'tensorflow.python.distribute' (C:Users33651AppDataRoamingPythonPython37site-packagestensorflowpythondistribute__init__.py)
关于如何解决它的任何想法?
我在 Windows 10 上,使用 Anaconda,Python 3.7,tensorflow 版本为 2.3.1,
numpy 版本为 1.19.2 tensorflow_hub 版本为 0.10.0 tensorflow_hub 版本 0.8.0 出现同样的错误
回答
我遇到了同样的问题,通过将我环境中的 tensorflow-estimator 版本从 2.4.0 降级到 2.3.0 解决了这个问题。我能够在 Anaconda Navigator 中很容易地做到这一点,但这可以通过使用 pip 在任何其他环境/包管理器中完成:
pip install --upgrade tensorflow-estimator==2.3.0
注意:--upgrade适用于升级和降级。
以上是尝试导入tensorflow_hub时出现此错误:无法从'tensorflow.python.distribute'导入名称'parameter_server_strategy_v2'的全部内容。
THE END
二维码