前提・実現したいこと
kerasのVGG16の分類モデルを回帰モデルに転用したい
発生しているエラーメッセージの原因を理解して、エラーメッセージを吐かないようにしたい。
発生している問題・エラーメッセージ
定義したモデルに64×64のRGB画像を学習用として投げ、
input_shape = (256, 256, 3)で以下の定義したモデルに転用したところ
main_model.fit(x=x_train, y=y_train, epochs=10, verbose=2, validation_data=(x_test, y_test))
の入力に
Error when checking target: expected dense_2 to have shape (1,) but got array with shape (2,)
と表示され、学習ができない
該当のソースコード
python3.6
1###レイヤーの定義 2def VGG16_Reg(input_shape): 3 input_layer = Input(shape=input_shape) 4 5 # Block 1 6 conv1_1 = Conv2D(64, (3, 3), name='conv1_1', activation='relu', padding='same')(input_layer) 7 conv1_2 = Conv2D(64, (3, 3), name='conv1_2', activation='relu', padding='same')(conv1_1) 8 bn1 = BatchNormalization(axis=3)(conv1_2) 9 pool1 = MaxPooling2D(pool_size=(2, 2))(bn1) 10 drop1 = Dropout(0.5)(pool1) 11 12 # Block 2 13 conv2_1 = Conv2D(128, (3, 3), name='conv2_1', activation='relu', padding='same')(drop1) 14 conv2_2 = Conv2D(128, (3, 3),name='conv2_2', activation='relu', padding='same')(conv2_1) 15 bn2 = BatchNormalization(axis=3)(conv2_2) 16 pool2 = MaxPooling2D(pool_size=(2, 2))(bn2) 17 drop2 = Dropout(0.5)(pool2) 18 19 # Block 3 20 conv3_1 = Conv2D(256, (3, 3),name='conv3_1', activation='relu', padding='same')(drop2) 21 conv3_2 = Conv2D(256, (3, 3),name='conv3_2', activation='relu', padding='same')(conv3_1) 22 conv3_3 = Conv2D(256, (3, 3),name='conv3_3', activation='relu', padding='same')(conv3_2) 23 conv3_4 = Conv2D(256, (3, 3),name='conv3_4', activation='relu', padding='same')(conv3_3) 24 bn3 = BatchNormalization(axis=3)(conv3_4) 25 pool3 = MaxPooling2D(pool_size=(2, 2))(bn3) 26 drop3 = Dropout(0.5)(pool3) 27 28 # Block 4 29 conv4_1 = Conv2D(512, (3, 3),name='conv4_1', activation='relu', padding='same')(drop3) 30 conv4_2 = Conv2D(512, (3, 3),name='conv4_2', activation='relu', padding='same')(conv4_1) 31 conv4_3 = Conv2D(512, (3, 3),name='conv4_3', activation='relu', padding='same')(conv4_2) 32 conv4_4 = Conv2D(512, (3, 3),name='conv4_4', activation='relu', padding='same')(conv4_3) 33 bn4 = BatchNormalization(axis=3)(conv4_4) 34 pool4 = MaxPooling2D(pool_size=(2, 2))(bn4) 35 drop4 = Dropout(0.5)(pool4) 36 37 # Block 5 38 conv5_1 = Conv2D(512, (3, 3),name='conv5_1', activation='relu', padding='same')(drop4) 39 conv5_2 = Conv2D(512, (3, 3),name='conv5_2', activation='relu', padding='same')(conv5_1) 40 conv5_3 = Conv2D(512, (3, 3),name='conv5_3', activation='relu', padding='same')(conv5_2) 41 conv5_4 = Conv2D(512, (3, 3),name='conv5_4', activation='relu', padding='same')(conv5_3) 42 bn5 = BatchNormalization(axis=3)(conv5_4) 43 pool5 = MaxPooling2D(pool_size=(2, 2))(bn5) 44 drop5 = Dropout(0.5)(pool5) 45 46 x = Flatten()(drop5) 47 x = Dense(4096)(x) 48 x = Dropout(0.5)(x) 49 x = Dense(1)(x) 50 model = Model(inputs=input_layer, outputs=x) 51 model.compile(loss='mean_squared_error', optimizer='rmsprop') 52 return model 53
補足情報
google colabで実行
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/15 14:16
2019/12/15 14:24
2019/12/15 14:31
2019/12/15 14:33
2019/12/15 15:28 編集
2019/12/15 15:29
2019/12/15 16:39