首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试导入tensorflow_hub时出现此错误:无法从'tensorflow.python.distribute‘导入名称'parameter_server_strategy_v2’

尝试导入tensorflow_hub时出现此错误:无法从'tensorflow.python.distribute‘导入名称'parameter_server_strategy_v2’
EN

Stack Overflow用户
提问于 2020-11-29 01:16:32
回答 3查看 4.5K关注 0票数 5

我运行了以下代码:

代码语言:javascript
运行
复制
import tensorflow_hub as hub

我得到了这个错误:

代码语言:javascript
运行
复制
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-5c017171c13e> in <module>
----> 1 import tensorflow_hub as hub

~\anaconda3\envs\Python 3-7\lib\site-packages\tensorflow_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

~\anaconda3\envs\Python 3-7\lib\site-packages\tensorflow_hub\estimator.py in <module>
     60 
     61 
---> 62 class LatestModuleExporter(tf.compat.v1.estimator.Exporter):
     63   """Regularly exports registered modules into timestamped directories.
     64 

~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\util\lazy_loader.py in __getattr__(self, item)
     60 
     61   def __getattr__(self, item):
---> 62     module = self._load()
     63     return getattr(module, item)
     64 

~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\util\lazy_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 

~\anaconda3\envs\Python 3-7\lib\importlib\__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_estimator\python\estimator\api\__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

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_estimator\python\estimator\api\_v1\estimator\__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

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_estimator\python\estimator\api\_v1\estimator\experimental\__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

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_estimator\python\estimator\canned\dnn.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

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_estimator\python\estimator\estimator.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

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_estimator\python\estimator\run_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:\Users\33651\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\__init__.py)

有没有办法解决这个问题?

我使用的是windows 10,Anaconda,Python 3.7,tensorflow版本是2.3.1,

tensorflow_hub版本为1.19.2 tensorflow_hub版本为0.10.0与numpy版本0.8.0的错误相同

EN

回答 3

Stack Overflow用户

发布于 2021-01-20 01:07:14

我也遇到了同样的问题,通过在我的环境中将tensorflow-estimator版本从2.4.0降级到2.3.0,这个问题得到了解决。我可以在Anaconda Navigator中很容易地做到这一点,但在任何其他环境/包管理器中,使用pip也可以做到这一点:

代码语言:javascript
运行
复制
pip install --upgrade tensorflow-estimator==2.3.0

注意:--upgrade适用于升级和降级。

票数 9
EN

Stack Overflow用户

发布于 2021-01-06 19:28:27

我相信您安装了错误的tensorflow-estimator版本: pip包tensorflow 2.3.1需要tensorflow-estimator<2.4.0,>=2.3.0,但是...\site-packages\tensorflow_estimator\python\estimator\run_config.py第30行的违规导入来自tensorflow-estimator 2.4.0。

票数 2
EN

Stack Overflow用户

发布于 2022-02-23 18:10:11

我认为你应该使用相同版本的tensorflow,Keras

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65052400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档