我正在尝试构建 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()