DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Functional)利用MNIST(手写数字图片识别)数据集实现多分类预测
生活随笔
收集整理的這篇文章主要介紹了
DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Functional)利用MNIST(手写数字图片识别)数据集实现多分类预测
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
DL之CNN:利用卷積神經(jīng)網(wǎng)絡(luò)算法(2→2,基于Keras的API-Functional)利用MNIST(手寫數(shù)字圖片識別)數(shù)據(jù)集實現(xiàn)多分類預(yù)測
?
?
?
目錄
輸出結(jié)果
設(shè)計思路
核心代碼
?
?
?
?
?
輸出結(jié)果
下邊兩張圖對應(yīng)查看,可知,數(shù)字0有965個是被準確識別到!
?
1.10.0 Size of: - Training-set: 55000 - Validation-set: 5000 - Test-set: 10000 Epoch 1/1128/55000 [..............................] - ETA: 14:24 - loss: 2.3439 - acc: 0.0938256/55000 [..............................] - ETA: 14:05 - loss: 2.2695 - acc: 0.1016384/55000 [..............................] - ETA: 13:20 - loss: 2.2176 - acc: 0.1302512/55000 [..............................] - ETA: 13:30 - loss: 2.1608 - acc: 0.2109640/55000 [..............................] - ETA: 13:29 - loss: 2.0849 - acc: 0.2500768/55000 [..............................] - ETA: 13:23 - loss: 2.0309 - acc: 0.2734896/55000 [..............................] - ETA: 13:30 - loss: 1.9793 - acc: 0.29461024/55000 [..............................] - ETA: 13:23 - loss: 1.9105 - acc: 0.33691152/55000 [..............................] - ETA: 13:22 - loss: 1.8257 - acc: 0.3776 …… 53760/55000 [============================>.] - ETA: 18s - loss: 0.2106 - acc: 0.9329 53888/55000 [============================>.] - ETA: 16s - loss: 0.2103 - acc: 0.9330 54016/55000 [============================>.] - ETA: 14s - loss: 0.2100 - acc: 0.9331 54144/55000 [============================>.] - ETA: 13s - loss: 0.2096 - acc: 0.9333 54272/55000 [============================>.] - ETA: 11s - loss: 0.2092 - acc: 0.9334 54400/55000 [============================>.] - ETA: 9s - loss: 0.2089 - acc: 0.9335 54528/55000 [============================>.] - ETA: 7s - loss: 0.2086 - acc: 0.9336 54656/55000 [============================>.] - ETA: 5s - loss: 0.2082 - acc: 0.9337 54784/55000 [============================>.] - ETA: 3s - loss: 0.2083 - acc: 0.9337 54912/55000 [============================>.] - ETA: 1s - loss: 0.2082 - acc: 0.9337 55000/55000 [==============================] - 837s 15ms/step - loss: 0.2080 - acc: 0.933832/10000 [..............................] - ETA: 21s160/10000 [..............................] - ETA: 8s 288/10000 [..............................] - ETA: 6s448/10000 [>.............................] - ETA: 5s576/10000 [>.............................] - ETA: 5s736/10000 [=>............................] - ETA: 4s864/10000 [=>............................] - ETA: 4s1024/10000 [==>...........................] - ETA: 4s1152/10000 [==>...........................] - ETA: 4s1312/10000 [==>...........................] - ETA: 4s1440/10000 [===>..........................] - ETA: 4s1600/10000 [===>..........................] - ETA: 3s1728/10000 [====>.........................] - ETA: 3s ……3008/10000 [========>.....................] - ETA: 3s3168/10000 [========>.....................] - ETA: 3s3296/10000 [========>.....................] - ETA: 3s3456/10000 [=========>....................] - ETA: 2s ……5248/10000 [==============>...............] - ETA: 2s5376/10000 [===============>..............] - ETA: 2s5536/10000 [===============>..............] - ETA: 2s5664/10000 [===============>..............] - ETA: 1s5792/10000 [================>.............] - ETA: 1s ……7360/10000 [=====================>........] - ETA: 1s7488/10000 [=====================>........] - ETA: 1s7648/10000 [=====================>........] - ETA: 1s7776/10000 [======================>.......] - ETA: 1s7936/10000 [======================>.......] - ETA: 0s8064/10000 [=======================>......] - ETA: 0s8224/10000 [=======================>......] - ETA: 0s ……9760/10000 [============================>.] - ETA: 0s9920/10000 [============================>.] - ETA: 0s 10000/10000 [==============================] - 4s 449us/step loss 0.05686537345089018 acc 0.982 acc: 98.20% [[ 965 0 4 0 0 0 4 1 2 4][ 0 1128 3 0 0 0 0 1 3 0][ 0 0 1028 0 0 0 0 1 3 0][ 0 0 10 991 0 2 0 2 3 2][ 0 0 3 0 967 0 1 1 1 9][ 2 0 1 7 1 863 5 1 4 8][ 2 3 0 0 3 2 946 0 2 0][ 0 1 17 1 1 0 0 987 2 19][ 2 0 9 2 0 1 0 1 955 4][ 1 4 3 2 8 0 0 0 1 990]]_________________________________________________________________ Layer (type) Output Shape Param # ================================================================= input_1 (InputLayer) (None, 784) 0 _________________________________________________________________ reshape (Reshape) (None, 28, 28, 1) 0 _________________________________________________________________ layer_conv1 (Conv2D) (None, 28, 28, 16) 416 _________________________________________________________________ max_pooling2d (MaxPooling2D) (None, 14, 14, 16) 0 _________________________________________________________________ layer_conv2 (Conv2D) (None, 14, 14, 36) 14436 _________________________________________________________________ max_pooling2d_1 (MaxPooling2 (None, 7, 7, 36) 0 _________________________________________________________________ flatten (Flatten) (None, 1764) 0 _________________________________________________________________ dense (Dense) (None, 128) 225920 _________________________________________________________________ dense_1 (Dense) (None, 10) 1290 ================================================================= Total params: 242,062 Trainable params: 242,062 Non-trainable params: 0 _________________________________________________________________ (5, 5, 1, 16) (1, 28, 28, 16)?
設(shè)計思路
?
?
?
核心代碼
后期更新……
path_model = 'Functional_model.keras' from tensorflow.python.keras.models import load_model model2_1 = load_model(path_model) model_weights_path = 'Functional_model_weights.keras' model2_1.save_weights(model_weights_path ) model2_1.load_weights(model_weights_path, by_name=True ) model2_1.load_weights(model_weights_path) 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)?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Functional)利用MNIST(手写数字图片识别)数据集实现多分类预测的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DL之CNN:利用卷积神经网络算法(2→
- 下一篇: ML之模型文件:机器学习、深度学习中常见