2016-11-24 159 views
1

我正在使用Resnet50做转移学习。后端是张量流。 我试图在RESNET叠放三个层,但失败,以下错误:Keras转移学习与Resnet50失败,异常

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)) 

回答

0

RESNET与include_top最后一层= False选项已经变平并且不需要另一个平坦化层。

+0

你确定吗? https://github.com/fchollet/keras/blob/89e6eb01f200ef6fa8db926ecfee68b37b229fbc/keras/applications/resnet50.py#L234 – Eduardo

0

在实例化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))