参考代码如下:
1、导入相关包
2、 随机种子确保结果可再现
3、 加载数据
4、定义模型函数
5、开始编译模型
6、 训练模型
7、评估模型
8、输出Loss值和评分
9、运行结果
Train on 60000 samples, validate on 10000 samples Epoch 1/10
6s - loss: 0.2400 - acc: 0.9314 - val_loss: 0.0837 - val_acc: 0.9740
Epoch 2/10
6s - loss: 0.0779 - acc: 0.9765 - val_loss: 0.0482 - val_acc: 0.9843
Epoch 3/10
6s - loss: 0.0560 - acc: 0.9827 - val_loss: 0.0431 - val_acc: 0.9861
Epoch 4/10
6s - loss: 0.0433 - acc: 0.9866 - val_loss: 0.0423 - val_acc: 0.9857
Epoch 5/10
6s - loss: 0.0363 - acc: 0.9883 - val_loss: 0.0333 - val_acc: 0.9884
Epoch 6/10
6s - loss: 0.0301 - acc: 0.9906 - val_loss: 0.0310 - val_acc: 0.9893
Epoch 7/10
6s - loss: 0.0246 - acc: 0.9922 - val_loss: 0.0316 - val_acc: 0.9888
Epoch 8/10
6s - loss: 0.0232 - acc: 0.9927 - val_loss: 0.0296 - val_acc: 0.9896
Epoch 9/10
6s - loss: 0.0195 - acc: 0.9937 - val_loss: 0.0284 - val_acc: 0.9906
Epoch 10/10
6s - loss: 0.0164 - acc: 0.9949 - val_loss: 0.0282 - val_acc: 0.9911
10000/10000 [==============================] - 1s 85us/step
Loss: 0.0281819745783
scores: 0.9911
领取专属 10元无门槛券
私享最新 技术干货