【问题标题】:Keras - Error loading pre-trained network using keras in Google ColabKeras - 在 Google Colab 中使用 keras 加载预训练网络时出错
【发布时间】:2021-08-19 21:58:04
【问题描述】:

我想使用 keras 库将预训练的网络加载到我的 Google Colab 笔记本中。

我为此使用以下代码:

import keras
from keras.applications import VGG16, InceptionResNetV2, ResNet50

我收到以下错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-52-9c551e8fe84f> in <module>()
     15 from keras.preprocessing.image import ImageDataGenerator
     16 
---> 17 from keras.applications import VGG16, InceptionResNetV2, ResNet50

ImportError: cannot import name 'VGG16' from 'keras.applications' (/usr/local/lib/python3.7/dist-packages/keras/applications/__init__.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

我曾经这样做并且效果很好,但现在它给出了错误。不知道是什么问题!

应该注意的是,当我使用 Jupyter notebook 在我的设备上执行此操作时,它运行良好并且网络加载,但在 Google Colab 中会出错。

【问题讨论】:

    标签: keras jupyter-notebook google-colaboratory transfer-learning pre-trained-model


    【解决方案1】:

    也许我回答得有点晚了,但我也遇到了类似的错误。您需要将VGG16 修复为vgg16,或者您可以选择:

    from keras.applications.vgg16 import VGG16
    from keras.applications import InceptionResNetV2, ResNet50
    

    它应该工作得很好(就像我的情况一样)

    【讨论】:

      猜你喜欢
      • 2020-12-10
      • 2021-04-20
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      • 2017-06-20
      • 2017-03-19
      相关资源
      最近更新 更多