2

我正在使用 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))
4

2 回答 2

1

实例化 Resnet 时必须显式 input_shape。 model = ResNet50(include_top=False, weights='imagenet',input_shape=(224,224,3))

如果您将 theano 作为后端,则必须将通道数设置为第一个: model = ResNet50(include_top=False, weights='imagenet',input_shape=(3,224,224))

于 2017-02-09T17:54:53.733 回答
1

带有 include_top=False 选项的最后一层 resnet 已经被展平,您不需要另一个展平层。

于 2017-01-24T06:52:43.980 回答