即使安装后 Tensorflow_hub 也不导入

Posted

技术标签:

【中文标题】即使安装后 Tensorflow_hub 也不导入【英文标题】:Tensorflow_hub not importing even after installing 【发布时间】:2022-01-13 15:52:09 【问题描述】:

我通过执行以下操作从 conda 安装了 TensorFlow_hub:conda install -c conda-forge tensorflow-hub

但是,当我尝试在任何地方导入 tensorflow_hub 时,出现此错误;

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_14843/980229998.py in <module>
      1 import tensorflow as tf
----> 2 import tensorflow_hub as hub

~/anaconda3/envs/PoseEstimation/lib/python3.9/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/PoseEstimation/lib/python3.9/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 

~/anaconda3/envs/PoseEstimation/lib/python3.9/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 

~/anaconda3/envs/PoseEstimation/lib/python3.9/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/PoseEstimation/lib/python3.9/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

~/anaconda3/envs/PoseEstimation/lib/python3.9/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

~/anaconda3/envs/PoseEstimation/lib/python3.9/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

~/anaconda3/envs/PoseEstimation/lib/python3.9/site-packages/tensorflow_estimator/__init__.py in <module>
      8 import sys as _sys
      9 
---> 10 from tensorflow_estimator._api.v1 import estimator
     11 
     12 del _print_function

~/anaconda3/envs/PoseEstimation/lib/python3.9/site-packages/tensorflow_estimator/_api/v1/estimator/__init__.py in <module>
     11 from tensorflow_estimator._api.v1.estimator import export
     12 from tensorflow_estimator._api.v1.estimator import inputs
---> 13 from tensorflow_estimator._api.v1.estimator import tpu
     14 from tensorflow_estimator.python.estimator.canned.baseline import BaselineClassifier
     15 from tensorflow_estimator.python.estimator.canned.baseline import BaselineEstimator

~/anaconda3/envs/PoseEstimation/lib/python3.9/site-packages/tensorflow_estimator/_api/v1/estimator/tpu/__init__.py in <module>
     12 from tensorflow_estimator.python.estimator.tpu.tpu_config import RunConfig
     13 from tensorflow_estimator.python.estimator.tpu.tpu_config import TPUConfig
---> 14 from tensorflow_estimator.python.estimator.tpu.tpu_estimator import TPUEstimator
     15 from tensorflow_estimator.python.estimator.tpu.tpu_estimator import TPUEstimatorSpec
     16 

~/anaconda3/envs/PoseEstimation/lib/python3.9/site-packages/tensorflow_estimator/python/estimator/tpu/tpu_estimator.py in <module>
    106 
    107 # Track the adoption of TPUEstimator
--> 108 _tpu_estimator_gauge = tf.compat.v2.__internal__.monitoring.BoolGauge(
    109     '/tensorflow/api/tpu_estimator',
    110     'Whether the program uses tpu estimator or not.')

AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'monitoring'

我在当前环境下按照 conda list 列出的 TensorFlow 版本如下:

张量流 2.4.1 tensorflow-base 2.4.1 张量流估计器 2.6.0 张量流-GPU 2.4.1 tensorflow-hub 0.12.0

我该怎么做才能导入 tfhub 没有任何错误?

谢谢

【问题讨论】:

【参考方案1】:

下面提到的环境适合我

tensorflow-2.4.1 tensorflow-estimator-2.4.0 tensorflow-gpu-2.4.1 tensorflow-hub-0.12.0

将 tensorflow-estimator 降级到 2.4.0

【讨论】:

以上是关于即使安装后 Tensorflow_hub 也不导入的主要内容,如果未能解决你的问题,请参考以下文章

即使导入,引导程序也不适用

ModuleNotFoundError:没有名为“tensorflow_hub”的模块

即使在安装 .NET 核心 SDK 后,Dotnet 命令也不起作用

Excel 2007 VSTO 加载项即使在成功安装后也不可见

Jupyter notebook Import tensorflow_hub error: No module named tensorflow.python.training.tracking

即使在代码编译后也不显示文本标签