【发布时间】:2019-11-04 22:18:04
【问题描述】:
我的(最新)Keras 安装和 TensorFlow 1.10 Keras API 安装中缺少许多记录在案的 Keras applications。 我按照建议导入 Keras 的应用程序模块并按如下方式使用它:
from keras import applications
resnet = applications.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
我也试过
resnet = applications.resnext.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
但在这两种情况下,我都会遇到相同类型的错误:
AttributeError: module 'keras.applications' has no attribute 'ResNeXt101'
打印help(applications) 产量:
Help on package keras.applications in keras:
NAME
keras.applications
PACKAGE CONTENTS
densenet
imagenet_utils
inception_resnet_v2
inception_v3
mobilenet
mobilenet_v2
mobilenetv2
nasnet
resnet50
vgg16
vgg19
xception
FUNCTIONS
DenseNet121 = wrapper(*args, **kwargs)
DenseNet169 = wrapper(*args, **kwargs)
DenseNet201 = wrapper(*args, **kwargs)
InceptionResNetV2 = wrapper(*args, **kwargs)
InceptionV3 = wrapper(*args, **kwargs)
MobileNet = wrapper(*args, **kwargs)
MobileNetV2 = wrapper(*args, **kwargs)
NASNetLarge = wrapper(*args, **kwargs)
NASNetMobile = wrapper(*args, **kwargs)
ResNet50 = wrapper(*args, **kwargs)
VGG16 = wrapper(*args, **kwargs)
VGG19 = wrapper(*args, **kwargs)
Xception = wrapper(*args, **kwargs)
keras_modules_injection(base_fun)
这表明模型最初不存在于我的安装中。为什么不?它们也没有打包在 TensorFlow 的 Keras API 中。
我尝试从Keras applications GitHub repository 复制文件并将它们粘贴到site-packages/keras/applications/,但这会导致以下堆栈跟踪:
File "myscript.py", line 517, in get_fpn
resnet = applications.resnext.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
File "site-packages/keras/applications/resnet_common.py", line 575, in ResNeXt101
**kwargs)
File "site-packages/keras/applications/resnet_common.py", line 348, in ResNet
data_format=backend.image_data_format(),
AttributeError: 'NoneType' object has no attribute 'image_data_format'
关于如何解决这个问题的任何想法?为什么在 Keras 或 TensorFlow 的默认安装中不包含这些并在其中工作?为什么文档没有解释这一点?
【问题讨论】:
-
我看到您正在删除并重新发布您的问题,您不应该这样做。
-
是的,我知道这不好,但我和未来遇到同样问题的人确实得到了很好的答案
标签: python tensorflow keras python-module