我正在使用 Resnet50 进行迁移学习。后端是张量流。我试图在 Resnet 上再堆叠三层,但失败并出现以下错误:
Exception: The shape of the input to "Flatten" is not fully defined (got (None, None, 2048).
Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.
堆叠两个模型的代码如下:
model = ResNet50(include_top=False, weights='imagenet')
top_model = Sequential()
top_model.add(Flatten(input_shape=model.output_shape[1:]))
top_model.add(Dense(256, activation='relu'))
top_model.add(Dropout(0.5))
top_model.add(Dense(1, activation='sigmoid'))
top_model.load_weights(top_model_weights_path)
model = Model(input=model.input, output=top_model(model.output))