ImportError:无法导入名称'resnet'

时间:2019-11-12 10:45:35

标签: python tensorflow

发生此错误,而我的原始代码不包含“ import 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'

5 个答案:

答案 0 :(得分:1)

这是因为未安装resnet。您可以尝试使用pip安装它吗?

pip3 install resnet

答案 1 :(得分:1)

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

答案 2 :(得分:0)

代替

from tensorflow.python.keras.applications.resnet import ResNet50

尝试

from tensorflow.python.keras.applications.resnet50 import ResNet50

答案 3 :(得分:0)

在安装Keras-Applications==1.0.6后,我遇到了同样的情况,并且 Keras-Preprocessing==1.0.5。删除这两个pip程序包并重新安装tensorflow可解决此问题。

答案 4 :(得分:0)

尝试 resnet 而不是 resnet50

from keras.applications import resnet
model = resnet.ResNet50