【问题标题】:Keras : Create MobileNet_V2 model "AttributeError"Keras:创建 MobileNet_V2 模型“AttributeError”
【发布时间】:2018-10-09 09:03:23
【问题描述】:

我已经使用 keras 成功构建了几个基于 mobileNet 的模型。我注意到 Keras 2.2.0 中添加了 MobileNet_V2,但我无法使其工作:

from keras.applications.mobilenet_v2 import mobilenet_v2

base_model = mobilenet_v2.MobileNetV2(weights='imagenet', include_top=False)

我收到以下错误:AttributeError: 'NoneType' object has no attribute 'image_data_format' 在这条线上来自 mobilenet_v2.py data_format=backend.image_data_format()

在我看来backend有一个定义问题...我正在使用 Tensorflow 后端,也许它不适用于这个?

【问题讨论】:

  • 在终端中运行 keras.backend.image_data_format() 会返回什么? (导入 Keras 后)。
  • 它返回channels_last
  • 那么您应该提供一个重现此问题的示例,您是否定义了一个名为 backend 的变量?
  • 我提供的两行足以重现问题。在第二行,后端变量似乎被重置:backend = None 在 mobilenet_v2.py 的开头...
  • 好吧,这在 Keras 2.2.4 中失败了,我会在 github 中打开一个问题,因为它似乎是 Keras 本身的一个错误。

标签: python tensorflow keras


【解决方案1】:

问题来自于导入。正确的方法是执行以下操作:

from keras.applications import MobileNetV2
m = MobileNetV2(weights='imagenet', include_top=False)

【讨论】:

  • 当然,因为正如问题中所说,它仅在 2.2.0 之后才可用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-08
  • 2021-09-13
  • 2021-06-24
  • 2020-12-11
  • 2020-05-31
  • 1970-01-01
  • 2019-05-21
相关资源
最近更新 更多