DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Sequential)利用MNIST(手写数字图片识别)数据集实现多分类预测

DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Sequential)利用MNIST(手写数字图片识别)数据集实现多分类预测


输出结果

1.10.0
Size of:
- Training-set:55000
- Validation-set:5000
- Test-set:10000
Epoch 1/1
  128/55000 [..............................] - ETA: 15:39 - loss: 2.3021 - acc: 0.0703
  256/55000 [..............................] - ETA: 13:40 - loss: 2.2876 - acc: 0.1172
  384/55000 [..............................] - ETA: 14:24 - loss: 2.2780 - acc: 0.1328
  512/55000 [..............................] - ETA: 13:57 - loss: 2.2613 - acc: 0.1719
  640/55000 [..............................] - ETA: 13:57 - loss: 2.2414 - acc: 0.1828
  768/55000 [..............................] - ETA: 13:58 - loss: 2.2207 - acc: 0.2135
  896/55000 [..............................] - ETA: 14:01 - loss: 2.1926 - acc: 0.2467
 1024/55000 [..............................] - ETA: 13:34 - loss: 2.1645 - acc: 0.2725
 1152/55000 [..............................] - ETA: 13:38 - loss: 2.1341 - acc: 0.2969
 1280/55000 [..............................] - ETA: 13:40 - loss: 2.0999 - acc: 0.3273
 1408/55000 [..............................] - ETA: 13:37 - loss: 2.0555 - acc: 0.3629
……
54016/55000 [============================>.] - ETA: 15s - loss: 0.2200 - acc: 0.9350
54144/55000 [============================>.] - ETA: 13s - loss: 0.2198 - acc: 0.9350
54272/55000 [============================>.] - ETA: 11s - loss: 0.2194 - acc: 0.9351
54400/55000 [============================>.] - ETA: 9s - loss: 0.2191 - acc: 0.9352
54528/55000 [============================>.] - ETA: 7s - loss: 0.2189 - acc: 0.9352
54656/55000 [============================>.] - ETA: 5s - loss: 0.2185 - acc: 0.9354
54784/55000 [============================>.] - ETA: 3s - loss: 0.2182 - acc: 0.9354
54912/55000 [============================>.] - ETA: 1s - loss: 0.2180 - acc: 0.9355
55000/55000 [==============================] - 863s 16ms/step - loss: 0.2177 - acc: 0.9356

   32/10000 [..............................] - ETA: 22s
  160/10000 [..............................] - ETA: 8s
  288/10000 [..............................] - ETA: 6s
  416/10000 [>.............................] - ETA: 5s
  544/10000 [>.............................] - ETA: 5s
  672/10000 [=>............................] - ETA: 5s
  800/10000 [=>............................] - ETA: 5s
  928/10000 [=>............................] - ETA: 4s
 1056/10000 [==>...........................] - ETA: 4s
 1184/10000 [==>...........................] - ETA: 4s
 1312/10000 [==>...........................] - ETA: 4s
 1440/10000 [===>..........................] - ETA: 4s
……
 9088/10000 [==========================>...] - ETA: 0s
 9216/10000 [==========================>...] - ETA: 0s
 9344/10000 [===========================>..] - ETA: 0s
 9472/10000 [===========================>..] - ETA: 0s
 9600/10000 [===========================>..] - ETA: 0s
 9728/10000 [============================>.] - ETA: 0s
 9856/10000 [============================>.] - ETA: 0s
 9984/10000 [============================>.] - ETA: 0s
10000/10000 [==============================] - 5s 489us/step
loss 0.060937872195523234
acc 0.9803
acc: 98.03%
[[ 963    0    0    1    1    0    4    1    4    6]
 [   0 1128    0    2    0    1    2    0    2    0]
 [   2    9 1006    1    1    0    0    3   10    0]
 [   1    0    2  995    0    3    0    5    2    2]
 [   0    1    0    0  977    0    0    1    0    3]
 [   2    0    0    7    0  874    3    1    1    4]
 [   2    3    0    0    6    1  943    0    3    0]
 [   0    5    7    3    1    1    0  990    1   20]
 [   4    1    3    3    2    1    7    2  944    7]
 [   4    6    0    4    9    1    0    1    1  983]]

设计思路

后期更新……

核心代码

后期更新……

result = model.evaluate(x=data.x_test,
                        y=data.y_test)

for name, value in zip(model.metrics_names, result):
    print(name, value)
print("{0}: {1:.2%}".format(model.metrics_names[1], result[1]))

y_pred = model.predict(x=data.x_test)
cls_pred = np.argmax(y_pred, axis=1)
plot_example_errors(cls_pred)
plot_confusion_matrix(cls_pred)     

images = data.x_test[0:9]
cls_true = data.y_test_cls[0:9]
y_pred = model.predict(x=images)
cls_pred = np.argmax(y_pred, axis=1)
title = 'MNIST(Sequential Model): plot predicted example, resl VS predict'
plot_images(title, images=images,
            cls_true=cls_true,
            cls_pred=cls_pred)
(0)

相关推荐