質問内容
機械学習の学習精度が上がらず困っています.
実験環境は以下の通りです.
- モデル構造やその他関数:こちらを参考にしました(ベースネットワークはCNNに変更↓).
- 入力画像サイズ:128×64(縦×横)
- 訓練データ数:約90万ペアの画像(MNISTではない)を使用.
- 検証用データ数:約6万ペア
- バッチサイズ:32
- エポック:100
変更したCNNのモデル構造です.
python
1 model = models.Sequential() 2 3 weight_decay = 1e-4 4 5 model.add( 6 layers.Conv2D( 7 filters=64, 8 kernel_size=(3, 3), 9 input_shape=(height, width, 1), 10 padding='same', 11 kernel_regularizer=regularizers.l2( 12 weight_decay), 13 activation='relu' 14 )) 15 16 17 model.add( 18 layers.Conv2D( 19 filters=32, 20 kernel_size=(3, 3), 21 padding='same', 22 kernel_regularizer=regularizers.l2( 23 weight_decay), 24 activation='relu' 25 )) 26 27 28 model.add( 29 layers.MaxPooling2D( 30 pool_size=(2, 2))) 31 32 33 model.add( 34 layers.Conv2D( 35 filters=16, 36 kernel_size=(3, 3), 37 padding='same', 38 kernel_regularizer=regularizers.l2( 39 weight_decay), 40 activation='relu' 41 )) 42 43 44 model.add( 45 layers.MaxPooling2D( 46 pool_size=(2, 2))) 47 48 49 model.add(layers.Dropout(0.4)) 50 51 52 model.add(layers.Flatten()) 53 54 55 model.add( 56 layers.Dense( 57 128, 58 activation='relu')) 59
次に示すものが,60エポックまでを実行した結果になります.
まだ,100エポックまでは学習できていないのですが,明らかにおかしな結果となっているため質問させていただきます.
Epoch 1/100 28203/28203 [==============================] - 909s 32ms/step - loss: 0.0054 - accuracy: 0.9973 - val_loss: 0.0869 - val_accuracy: 0.8809 Epoch 2/100 28203/28203 [==============================] - 927s 33ms/step - loss: 0.0055 - accuracy: 0.9967 - val_loss: 0.0871 - val_accuracy: 0.8823 Epoch 3/100 28203/28203 [==============================] - 934s 33ms/step - loss: 0.0080 - accuracy: 0.9928 - val_loss: 0.0870 - val_accuracy: 0.8823 Epoch 4/100 28203/28203 [==============================] - 931s 33ms/step - loss: 0.0088 - accuracy: 0.9916 - val_loss: 0.0859 - val_accuracy: 0.8820 Epoch 5/100 28203/28203 [==============================] - 922s 33ms/step - loss: 0.0127 - accuracy: 0.9859 - val_loss: 0.0850 - val_accuracy: 0.8806 Epoch 6/100 28203/28203 [==============================] - 915s 32ms/step - loss: 0.0176 - accuracy: 0.9788 - val_loss: 0.0805 - val_accuracy: 0.8817 Epoch 7/100 28203/28203 [==============================] - 922s 33ms/step - loss: 0.0178 - accuracy: 0.9785 - val_loss: 0.0773 - val_accuracy: 0.8798 Epoch 8/100 28203/28203 [==============================] - 934s 33ms/step - loss: 0.0221 - accuracy: 0.9745 - val_loss: 0.0685 - val_accuracy: 0.8861 Epoch 9/100 28203/28203 [==============================] - 909s 32ms/step - loss: 0.0317 - accuracy: 0.9674 - val_loss: 0.0496 - val_accuracy: 0.9331 Epoch 10/100 28203/28203 [==============================] - 916s 32ms/step - loss: 0.0462 - accuracy: 0.9602 - val_loss: 0.6956 - val_accuracy: 0.0393 Epoch 11/100 28203/28203 [==============================] - 932s 33ms/step - loss: 0.0543 - accuracy: 0.9574 - val_loss: 0.9462 - val_accuracy: 0.0393 Epoch 12/100 28203/28203 [==============================] - 915s 32ms/step - loss: 0.0479 - accuracy: 0.9583 - val_loss: 0.9610 - val_accuracy: 0.0393 Epoch 13/100 28203/28203 [==============================] - 920s 33ms/step - loss: 0.0467 - accuracy: 0.9588 - val_loss: 0.9506 - val_accuracy: 0.0393 Epoch 14/100 28203/28203 [==============================] - 920s 33ms/step - loss: 0.0456 - accuracy: 0.9590 - val_loss: 0.9570 - val_accuracy: 0.0393 Epoch 15/100 28203/28203 [==============================] - 944s 33ms/step - loss: 0.0457 - accuracy: 0.9590 - val_loss: 0.9527 - val_accuracy: 0.0393 Epoch 16/100 28203/28203 [==============================] - 920s 33ms/step - loss: 0.0456 - accuracy: 0.9587 - val_loss: 0.9543 - val_accuracy: 0.0393 Epoch 17/100 28203/28203 [==============================] - 903s 32ms/step - loss: 0.0450 - accuracy: 0.9588 - val_loss: 0.9430 - val_accuracy: 0.0393 Epoch 18/100 28203/28203 [==============================] - 934s 33ms/step - loss: 0.0449 - accuracy: 0.9585 - val_loss: 0.9051 - val_accuracy: 0.0393 Epoch 19/100 28203/28203 [==============================] - 934s 33ms/step - loss: 0.0457 - accuracy: 0.9575 - val_loss: 0.9381 - val_accuracy: 0.0393 Epoch 20/100 28203/28203 [==============================] - 911s 32ms/step - loss: 0.0465 - accuracy: 0.9566 - val_loss: 0.9509 - val_accuracy: 0.0393 Epoch 21/100 28203/28203 [==============================] - 933s 33ms/step - loss: 0.0465 - accuracy: 0.9564 - val_loss: 0.9289 - val_accuracy: 0.0393 Epoch 22/100 28203/28203 [==============================] - 934s 33ms/step - loss: 0.0458 - accuracy: 0.9575 - val_loss: 0.9283 - val_accuracy: 0.0393 Epoch 23/100 28203/28203 [==============================] - 915s 32ms/step - loss: 0.0452 - accuracy: 0.9576 - val_loss: 0.9506 - val_accuracy: 0.0393 Epoch 24/100 28203/28203 [==============================] - 904s 32ms/step - loss: 0.0455 - accuracy: 0.9578 - val_loss: 0.9145 - val_accuracy: 0.0393 Epoch 25/100 28203/28203 [==============================] - 933s 33ms/step - loss: 0.0455 - accuracy: 0.9576 - val_loss: 0.9443 - val_accuracy: 0.0393 Epoch 26/100 28203/28203 [==============================] - 923s 33ms/step - loss: 0.0455 - accuracy: 0.9577 - val_loss: 0.9385 - val_accuracy: 0.0393 Epoch 27/100 28203/28203 [==============================] - 934s 33ms/step - loss: 0.0455 - accuracy: 0.9574 - val_loss: 0.9581 - val_accuracy: 0.0393 Epoch 28/100 28203/28203 [==============================] - 906s 32ms/step - loss: 0.0457 - accuracy: 0.9571 - val_loss: 0.9508 - val_accuracy: 0.0393 Epoch 29/100 28203/28203 [==============================] - 933s 33ms/step - loss: 0.0459 - accuracy: 0.9563 - val_loss: 0.8768 - val_accuracy: 0.0393 Epoch 30/100 28203/28203 [==============================] - 915s 32ms/step - loss: 0.0455 - accuracy: 0.9565 - val_loss: 0.9283 - val_accuracy: 0.0393 Epoch 31/100 28203/28203 [==============================] - 918s 33ms/step - loss: 0.0452 - accuracy: 0.9571 - val_loss: 0.9602 - val_accuracy: 0.0393 Epoch 32/100 28203/28203 [==============================] - 919s 33ms/step - loss: 0.0461 - accuracy: 0.9569 - val_loss: 0.9412 - val_accuracy: 0.0393 Epoch 33/100 28203/28203 [==============================] - 933s 33ms/step - loss: 0.0465 - accuracy: 0.9565 - val_loss: 0.9512 - val_accuracy: 0.0393 Epoch 34/100 28203/28203 [==============================] - 925s 33ms/step - loss: 0.0471 - accuracy: 0.9563 - val_loss: 0.9471 - val_accuracy: 0.0393 Epoch 35/100 28203/28203 [==============================] - 933s 33ms/step - loss: 0.0464 - accuracy: 0.9562 - val_loss: 0.9475 - val_accuracy: 0.0393 Epoch 36/100 28203/28203 [==============================] - 915s 32ms/step - loss: 0.0464 - accuracy: 0.9567 - val_loss: 0.8290 - val_accuracy: 0.0385 Epoch 37/100 28203/28203 [==============================] - 932s 33ms/step - loss: 0.0462 - accuracy: 0.9568 - val_loss: 0.9415 - val_accuracy: 0.0393 Epoch 38/100 28203/28203 [==============================] - 923s 33ms/step - loss: 0.0463 - accuracy: 0.9568 - val_loss: 0.9611 - val_accuracy: 0.0385 Epoch 39/100 28203/28203 [==============================] - 919s 33ms/step - loss: 0.0468 - accuracy: 0.9565 - val_loss: 0.9611 - val_accuracy: 0.0393 Epoch 40/100 28203/28203 [==============================] - 923s 33ms/step - loss: 0.0479 - accuracy: 0.9571 - val_loss: 0.9608 - val_accuracy: 0.0393 Epoch 41/100 28203/28203 [==============================] - 924s 33ms/step - loss: 0.5128 - accuracy: 0.4930 - val_loss: 0.9604 - val_accuracy: 0.0393 Epoch 42/100 28203/28203 [==============================] - 921s 33ms/step - loss: 0.9586 - accuracy: 0.0410 - val_loss: 0.9604 - val_accuracy: 0.0393 Epoch 43/100 28203/28203 [==============================] - 922s 33ms/step - loss: 0.9586 - accuracy: 0.0410 - val_loss: 0.9604 - val_accuracy: 0.0393 Epoch 44/100 28203/28203 [==============================] - 939s 33ms/step - loss: 0.9586 - accuracy: 0.0410 - val_loss: 0.9604 - val_accuracy: 0.0393 (同じ結果なので省略) Epoch 58/100 28203/28203 [==============================] - 932s 33ms/step - loss: 0.9586 - accuracy: 0.0410 - val_loss: 0.9604 - val_accuracy: 0.0393 Epoch 59/100 28203/28203 [==============================] - 922s 33ms/step - loss: 0.9586 - accuracy: 0.0410 - val_loss: 0.9604 - val_accuracy: 0.0393 Epoch 60/100 28203/28203 [==============================] - 915s 32ms/step - loss: 0.9586 - accuracy: 0.0410 - val_loss: 0.9604 - val_accuracy: 0.0393
9エポックまではlossとval_lossは比較的低い値なのですが,10エポック以降では急激にval_lossが大きな値をとり,41エポック以降はlossも大きな値をとるようになってしまっています.正解率も途中まではよかったのですが,いきなり0付近の値になってしまいます.
これは何が原因で起こってしまっている問題なのでしょうか.
また,何をどのように改善するとよいのかご教授いただければ幸いです.
補足情報(FW/ツールのバージョンなど)
ubuntu 20.04
Python 3.8.10
tensorflow-gpu 2.5.3
keras 2.8.0
numpy 1.19.5
jupyter lab 2.3.2
追記1
バッチサイズを128に増やした結果です.
追記2
バッチサイズを32にした結果です.
データ数は約7万にし,同じクラス・違うクラスでほぼ同じ割合でペアを作成しています.
回答2件
あなたの回答
tips
プレビュー