AttributeError: 'NoneType' object has no attribute 'image_data_format' in keras resnet50

主宰稳场 提交于 2021-02-04 06:32:24

问题


I am trying to use Resnet50 model for training.

from keras import backend as K
from keras_applications.resnet50 import ResNet50
from keras.layers import Input
from keras.callbacks import ModelCheckpoint

K.set_image_data_format('channels_last')
K.set_image_dim_ordering('tf')

input_layer = Input(shape=(224, 224, 3))
model = ResNet50(include_top=True, weights=None, classes=2)
model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['accuracy'])

Why is the following error showing up?

Using TensorFlow backend.
Traceback (most recent call last):
File "model.py", line 42, in <module>
model = ResNet50(include_top=True, weights=None, input_tensor=input_layer, classes=2)
File "/home/mario/.local/lib/python3.6/site-packages/keras_applications/resnet50.py", line 209, in ResNet50
data_format=backend.image_data_format(),
AttributeError: 'NoneType' object has no attribute 'image_data_format'

回答1:


I hit a similar issue. It worked by changing keras_applications to keras.applications.

They have an issue on GitHub and still open: https://github.com/keras-team/keras-applications/issues/54




回答2:


I hit this issue as well.

Please try this. It works very well:

from keras.applications.resnet50 import ResNet50


来源:https://stackoverflow.com/questions/54064897/attributeerror-nonetype-object-has-no-attribute-image-data-format-in-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!