DL 3 Ks
DL 3 Ks
DL 3 Ks
#Roll No: 15
#Batch: B1 [IT]
[3]: #Build the Image classification model by dividing the model into following 4␣
↪stages:
[9]: print(X_train.shape)
(60000, 28, 28)
1
[11]: X_train = (X_train - 0.0) / (255.0 - 0.0)
X_test = (X_test - 0.0) / (255.0 - 0.0)
X_train[0].min(), X_train[0].max()
(0.0, 1.0)
[20]: y_train[0:20]
2
c=np.array([5, 0, 4, 1, 9, 2, 1, 3, 1, 4, 3, 5, 3, 6, 1, 7, 2, 8, 6,␣
↪9],dtype='u1')
[23]:
model.summary()
Model: "sequential"
=================================================================
Total params: 542230 (2.07 MB)
Trainable params: 542230 (2.07 MB)
Non-trainable params: 0 (0.00 Byte)
Epoch 1/10
3
4000/4000 [==============================] - 26s 6ms/step - loss: 0.0044 -
accuracy: 0.9989
Epoch 2/10
4000/4000 [==============================] - 24s 6ms/step - loss: 0.0020 -
accuracy: 0.9996
Epoch 3/10
4000/4000 [==============================] - 27s 7ms/step - loss: 0.0018 -
accuracy: 0.9996
Epoch 4/10
4000/4000 [==============================] - 27s 7ms/step - loss: 8.3403e-04 -
accuracy: 0.9998
Epoch 5/10
4000/4000 [==============================] - 25s 6ms/step - loss: 4.2142e-04 -
accuracy: 0.9999
Epoch 6/10
4000/4000 [==============================] - 26s 7ms/step - loss: 1.9528e-04 -
accuracy: 1.0000
Epoch 7/10
4000/4000 [==============================] - 30s 7ms/step - loss: 1.3558e-04 -
accuracy: 1.0000
Epoch 8/10
4000/4000 [==============================] - 33s 8ms/step - loss: 1.0930e-04 -
accuracy: 1.0000
Epoch 9/10
4000/4000 [==============================] - 34s 9ms/step - loss: 9.6641e-05 -
accuracy: 1.0000
Epoch 10/10
4000/4000 [==============================] - 25s 6ms/step - loss: 8.5826e-05 -
accuracy: 1.0000
[41]: plt.figure(figsize=(16, 10))
for i in range(20):
image = random.choice(X_test).squeeze()
digit = np.argmax(model.predict(image.reshape((1, 28, 28, 1)))[0], axis=-1)
plot_digit(image, digit, plt, i)
plt.show()
4
1/1 [==============================] - 0s 17ms/step
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 23ms/step
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 19ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 18ms/step
1/1 [==============================] - 0s 20ms/step
[42]: 0.9896
[43]: n=random.randint(0,9999)
plt.imshow(X_test[n])
plt.show()
5
[44]: predicted_value=model.predict(X_test)
print("Handwritten number in the image is= %d" %np.argmax(predicted_value[n]))