Task Digits Numbers
Task Digits Numbers
Task Digits Numbers
...,
...,
In [6]: print(len(digits[0][1]))
60000
In [7]: print(len(x_train),len(y_train))
print(len(x_test),len(y_test))
print(x_train[0].shape)
print(x_test[0].shape)
60000 60000
10000 10000
(28, 28)
(28, 28)
In [11]: plt.figure(figsize=(10,10))
for i in range(25):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(x_train[i], cmap=plt.cm.binary)
plt.show()
In [13]: model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
Epoch 1/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0136 - accuracy: 0.9956
Epoch 2/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0116 - accuracy: 0.9965
Epoch 3/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0095 - accuracy: 0.9971
Epoch 4/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0097 - accuracy: 0.9969
Epoch 5/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0079 - accuracy: 0.9977
Epoch 6/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0067 - accuracy: 0.9979
Epoch 7/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0074 - accuracy: 0.9975
Epoch 8/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0058 - accuracy: 0.9982
Epoch 9/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0046 - accuracy: 0.9986
Epoch 10/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0070 - accuracy: 0.9975
Epoch 11/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0037 - accuracy: 0.9989
Epoch 12/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0061 - accuracy: 0.9980
Epoch 13/15
1875/1875 [==============================] - 3s 1ms/step - loss: 0.0039 - accuracy: 0.9988
Epoch 14/15
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0048 - accuracy: 0.9985
Epoch 15/15
1875/1875 [==============================] - 3s 1ms/step - loss: 0.0049 - accuracy: 0.9984
<keras.callbacks.History at 0x16be8530370>
Out[15]:
predict = pred.predict(x_test)
In [19]: plt.matshow(x_test[0])
<matplotlib.image.AxesImage at 0x16be8533490>
Out[19]:
In [20]: np.argmax(predict[0])
7
Out[20]:
plt.imshow(img, cmap=plt.cm.binary)
predicted_label = np.argmax(predictions_array)
if predicted_label == true_label:
color = 'blue'
else:
color = 'red'
thisplot[predicted_label].set_color('red')
thisplot[true_label].set_color('blue')
In [22]: i = 0
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predict[i], y_test, x_test)
plt.subplot(1,2,2)
plot_value_array(i, predict[i], y_test)
plt.show()
In [23]: i = 3
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predict[i], y_test, x_test)
plt.subplot(1,2,2)
plot_value_array(i, predict[i], y_test)
plt.show()
In [24]: i = 12
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predict[i], y_test, x_test)
plt.subplot(1,2,2)
plot_value_array(i, predict[i], y_test)
plt.show()7
In [25]: num_rows = 5
num_cols = 3
num_images = num_rows*num_cols
plt.figure(figsize=(2*2*num_cols, 2*num_rows))
for i in range(num_images):
plt.subplot(num_rows, 2*num_cols, 2*i+1)
plot_image(i, predict[i], y_test, x_test)
plt.subplot(num_rows, 2*num_cols, 2*i+2)
plot_value_array(i, predict[i], y_test)
plt.tight_layout()
plt.show()
In [26]: model.save("Digits_Recognize.h5")