ValueError:输入 0 与 flatten_4 层不兼容:预期 min_ndim=3,发现 ndim=2

时间:2021-01-16 16:55:21

标签: python

我正在尝试构建 resnet-50 模型,但出现以下错误:ValueError: Input 0 is incompatible with layer flatten_4: expected min_ndim=3, found ndim=2。谁能帮帮我。

这是我的代码:

from keras.models import Sequential
from keras.layers import Flatten, Dense, Dropout, BatchNormalization

input_shape=(224,224,3)
model = Sequential()

model.add(ResNet50(include_top=False,
                   input_tensor=None,
                   input_shape= input_shape,
                   pooling='avg',
                   classes=2,
                   weights=resnet_weights_path))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(BatchNormalization())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(BatchNormalization())
model.add(Dense(1, activation='sigmoid'))

model.layers[0].trainable = False
model.summary()

0 个答案:

没有答案