python - 导入错误 : cannot import name 'resnet'

标签 python tensorflow

发生此错误,而我的原始代码不包含“导入 resnet”。

似乎在导入 tensorflow 时发生了错误。

Traceback (most recent call last):
  File "step2_training.py", line 5, in <module>
    from class_coTrust import *
  File "/share/scratch/manqingdong/my_filename/class_coTrust.py", line 1, in <module>
    from utils import *
  File "/share/scratch/manqingdong/my_filename/utils.py", line 7, in <module>
    import tensorflow as tf
  File "/usr/lib64/python3.6/site-packages/tensorflow/__init__.py", line 98, in <module>
    from tensorflow_core import *
  File "/usr/lib64/python3.6/site-packages/tensorflow_core/__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/usr/lib64/python3.6/site-packages/tensorflow/__init__.py", line 50, in __getattr__
    module = self._load()
  File "/usr/lib64/python3.6/site-packages/tensorflow/__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/lib64/python3.6/site-packages/tensorflow_core/python/__init__.py", line 83, in <module>
    from tensorflow.python import keras
  File "/usr/lib64/python3.6/site-packages/tensorflow_core/python/keras/__init__.py", line 26, in <module>
    from tensorflow.python.keras import activations
  File "/usr/lib64/python3.6/site-packages/tensorflow_core/python/keras/__init__.py", line 27, in <module>
    from tensorflow.python.keras import applications
  File "/usr/lib64/python3.6/site-packages/tensorflow_core/python/keras/applications/__init__.py", line 64, in <module>
    from tensorflow.python.keras.applications.resnet import ResNet50
  File "/usr/lib64/python3.6/site-packages/tensorflow_core/python/keras/applications/resnet.py", line 22, in <module>
    from keras_applications import resnet
ImportError: cannot import name 'resnet'

最佳答案

tensorflow 2.4.0 的解决方案是from tensorflow.keras.applications import ResNet50

关于python - 导入错误 : cannot import name 'resnet' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58817026/

相关文章:

python - 给定中心点索引获取二维数组的子集

python - Tensorflow 可以用来检测图像中是否存在特定特征吗?

tensorflow - 使用 Keras 构建多变量、多任务 LSTM

python - 在错误的 python 版本上运行的 ML 引擎批量预测

python - Tensorflow tf.switch_case 不适用于 keras 输入

python - 从数据生成器返回 3 张图像

python - 如何使用 Kubernetes Python 客户端创建 secret ?

Python 3.5 MySQL 连接器

python - 如何在 python 中用空格替换所有那些特殊字符?

python - 如何在 Python 中第一次出现字母时拆分字符串?