1.加入DROPOUT功能
from keras.layers import Dropout
model.add(Dropout(0.5))
2.查看模型的摘要
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense_1 (Dense) (None, 1000) 785000
_________________________________________________________________
dropout_1 (Dropout) (None, 1000) 0
_________________________________________________________________
dense_2 (Dense) (None, 10) 10010
=================================================================
Total params: 795,010
Trainable params: 795,010
Non-trainable params: 0
_________________________________________________________________
None
3.查看训练过程的准确率
Epoch 1/10
– 7s – loss: 0.3587 – acc: 0.8914 – val_loss: 0.1662 – val_acc: 0.9541
Epoch 2/10
– 7s – loss: 0.1611 – acc: 0.9539 – val_loss: 0.1193 – val_acc: 0.9650
Epoch 3/10
– 7s – loss: 0.1165 – acc: 0.9655 – val_loss: 0.1000 – val_acc: 0.9699
Epoch 4/10
– 7s – loss: 0.0922 – acc: 0.9736 – val_loss: 0.0868 – val_acc: 0.9740
Epoch 5/10
– 7s – loss: 0.0731 – acc: 0.9783 – val_loss: 0.0824 – val_acc: 0.9741
Epoch 6/10
– 7s – loss: 0.0655 – acc: 0.9804 – val_loss: 0.0754 – val_acc: 0.9769
Epoch 7/10
– 6s – loss: 0.0550 – acc: 0.9835 – val_loss: 0.0731 – val_acc: 0.9774
Epoch 8/10
– 6s – loss: 0.0488 – acc: 0.9849 – val_loss: 0.0682 – val_acc: 0.9803
Epoch 9/10
– 6s – loss: 0.0429 – acc: 0.9867 – val_loss: 0.0685 – val_acc: 0.9801
Epoch 10/10
– 6s – loss: 0.0364 – acc: 0.9885 – val_loss: 0.0701 – val_acc: 0.9794
4.图示训练过程的准确率
无论是训练还是验证,准确率都越来越高
在Epoch训练后期,虽然”acc训练数据准确率”比”val_acc验证的准确率”高,但是”训练的准确率”与”验证的准确率”差距变小,过度拟合的程度已经减轻
5.查看准确率
32/10000 […………………………] – ETA: 0s
736/10000 [=>……………………….] – ETA: 0s
1536/10000 [===>……………………..] – ETA: 0s
2368/10000 [======>…………………..] – ETA: 0s
3200/10000 [========>…………………] – ETA: 0s
3968/10000 [==========>……………….] – ETA: 0s
4608/10000 [============>……………..] – ETA: 0s
5248/10000 [==============>……………] – ETA: 0s
6048/10000 [=================>…………] – ETA: 0s
6848/10000 [===================>……….] – ETA: 0s
7744/10000 [======================>…….] – ETA: 0s
8640/10000 [========================>…..] – ETA: 0s
9376/10000 [===========================>..] – ETA: 0s
9952/10000 [============================>.] – ETA: 0s
10000/10000 [==============================] – 1s 67us/step
accuracy= 0.9821
从以上执行结果可知准确率是0.98,比之前未加入DROPOUT时还高,这代表DROPOUT不但可以解决过度拟合的问题,还可以增加准确率