2016-11-24 4 views
1

私はResnet50を使って転送学習を行っています。バックエンドはテンソルフローです。 私はResnetの上に3つの以上の層を積み重ねることを試みたが、次のエラーで失敗する:Resnet50を使ったKeras Transferの学習は例外で失敗する

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. 

2つのモデルは、以下の通りです積み重ねるためのコード:

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

include_topとresnetの最後の層= Falseオプションは既に平坦化されており、別の平坦化レイヤーは必要ありません。

+0

をよろしいですか? https://github.com/fchollet/keras/blob/89e6eb01f200ef6fa8db926ecfee68b37b229fbc/keras/applications/resnet50.py#L234 – Eduardo

0

Resnetのインスタンス化時には、明示的にinput_shapeを指定する必要があります。あなたはtheanoバックエンドとしてあなたが最初のように、チャンネルの数を設定する必要がありますしている場合は model = ResNet50(include_top=False, weights='imagenet',input_shape=(224,224,3))

model = ResNet50(include_top=False, weights='imagenet',input_shape=(3,224,224))

関連する問題