【问题标题】:ImportError: cannot import name 'resnet' from 'tensorflow.python.keras.applications'ImportError:无法从“tensorflow.python.keras.applications”导入名称“resnet”
【发布时间】:2021-11-22 10:25:45
【问题描述】:

我一直在尝试实现this colab code,但在训练部分代码时遇到了这个错误。

(python版本Python 3.7.12和tensorflow版本1.14。)

!python3 /content/gun_detection/models/research/object_detection/model_main.py \
    --pipeline_config_path={config_path + pipeline_file} \
    --model_dir={model_dir} \
    --alsologtostderr \
    --num_train_steps={num_steps} \
    --num_eval_steps={num_eval_steps}

我收到此 ImportError 消息:

/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/usr/local/lib/python3.7/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.7/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Traceback (most recent call last):
  File "/content/gun_detection/models/research/object_detection/model_main.py", line 25, in <module>
    from object_detection import model_lib
  File "/content/gun_detection/models/research/object_detection/model_lib.py", line 30, in <module>
    from object_detection import exporter as exporter_lib
  File "/content/gun_detection/models/research/object_detection/exporter.py", line 24, in <module>
    from object_detection.builders import model_builder
  File "/content/gun_detection/models/research/object_detection/builders/model_builder.py", line 37, in <module>
    from object_detection.meta_architectures import deepmac_meta_arch
  File "/content/gun_detection/models/research/object_detection/meta_architectures/deepmac_meta_arch.py", line 19, in <module>
    from object_detection.models.keras_models import resnet_v1
  File "/content/gun_detection/models/research/object_detection/models/keras_models/resnet_v1.py", line 22, in <module>
    from tensorflow.python.keras.applications import resnet
ImportError: cannot import name 'resnet' from 'tensorflow.python.keras.applications' (/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/applications/__init__.py)

【问题讨论】:

    标签: python python-3.x tensorflow image-processing object-detection


    【解决方案1】:

    关注此document。 : tf.keras.applications.resnet 没有resnet

    你可以试试:

    from tf.keras.applications.resnet import ResNet50
    

    【讨论】:

    • 非常感谢您的回复。这样做,给了我错误:ModuleNotFoundError: No module named 'tf'
    • 虽然我已经这样做了:-import tensorflow as tf 然后尝试了from tf.keras.applications.resnet import ResNet50,仍然没有给出名为“tf”的模块。我是新来的。你知道为什么会这样吗?
    • 嗨,from tensorflow.keras.applications.resnet import ResNet50 怎么样
    • 不,亲爱的 :-( 它在同一个地方显示 ModuleNotFoundError: No module named 'tensorflow.keras.applications.resnet'。这个错误已经卡了好几个星期了。你知道其他替代解决方案吗?
    • 你好,建议你换个平台(比如colab)试试,看看是不是你个人设备的环境问题。
    【解决方案2】:

    您可以在这里查看Tensorflow Library

    Tensorflow 1.14 没有resnet。 正确的导入是:

    from tensorflow.keras.applications import resnet50
    

    【讨论】:

    • 先生,我试过了,但还是给了我一个错误ImportError: cannot import name 'resnet' from 'tensorflow.python.keras.applications' (/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/applications/__init__.py)。请问您对此有什么解决办法吗?
    • 如果 tensorflow 1.14 没有你所说的 resnet,那我应该使用哪个 tensorflow 版本?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2021-06-30
    • 2020-10-19
    • 2018-08-13
    • 2015-01-26
    • 2020-10-10
    • 2020-02-12
    相关资源
    最近更新 更多