我正在使用 Resnet50 进行迁移学习。后端是 tensorflow 。 我尝试在 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))
最佳答案
带有 include_top=False 选项的 resnet 的最后一层已经被展平,您不需要另一个展平层。
关于Keras 使用 Resnet50 进行迁移学习失败并出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40788298/