Mnist2.ipynb - Colaboratory
Mnist2.ipynb - Colaboratory
Mnist2.ipynb - Colaboratory
x_train==x_test.astype('float32')/255.0
x_test x_train.astype('float32')/255.0
# #
changes
255 = in
pixel
32 bit
values
memory
are integer values
x_test = x_test.astype('float32')/255.0 # changes in 32 bit memory
fig =
ax.set_title
plt.figure(figsize=
(y_train (5,3))
[i])
for i in range (15):
ax = fig.add_subplot(2,10, i+1, xticks=[], yticks=[])
ax.imshow(np.squeeze(x_train[i]), cmap='gray')
ax.set_title (y_train [i])
5 4 1 9 2 1 3 1 4
5047 21314
3 5 3 6 1
35360
https://colab.research.google.com/drive/11c1QESByXTYVJLqxlDd1l5aSeY90ptfS#scrollTo=h0QAcvWmndrb Page 1 of 6
mnist2.ipynb - Colaboratory 27/06/23, 6:40 PM
(28, 28, 1)
model = Sequential()
model.add(Conv2D(32, (3,3), activation='relu', input_shape=img_shape))
model.add(MaxPool2D((2, 2)))
model.add(Conv2D (48, (3,3), activation='relu'))
model.add(MaxPool2D ((2, 2)))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(500, activation='relu'))
model.add(Dense(10, activation='softmax'))
model.summary()
Model: "sequential_5"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_4 (Conv2D) (None, 26, 26, 32) 320
=================================================================
Total params: 619,702
Trainable params: 619,702
Non-trainable params: 0
_________________________________________________________________
InputLaver output:[(None,28,28,1)]
https://colab.research.google.com/drive/11c1QESByXTYVJLqxlDd1l5aSeY90ptfS#scrollTo=h0QAcvWmndrb Page 3 of 6
mnist2.ipynb - Colaboratory 27/06/23, 6:40 PM
Epoch 1/10
422/422 - 50s - loss: 0.2365 - accuracy: 0.9278 - val_loss: 0.0561 - val_accur
Epoch 2/10
422/422 - 43s - loss: 0.0813 - accuracy: 0.9744 - val_loss: 0.0398 - val_accur
Epoch 3/10
422/422 - 43s - loss: 0.0599 - accuracy: 0.9809 - val_loss: 0.0359 - val_accur
Epoch 4/10
422/422 - 44s - loss: 0.0472 - accuracy: 0.9844 - val_loss: 0.0305 - val_accur
Epoch 5/10
422/422 - 43s - loss: 0.0409 - accuracy: 0.9872 - val_loss: 0.0310 - val_accur
Epoch 6/10
422/422 - 44s - loss: 0.0356 - accuracy: 0.9881 - val_loss: 0.0309 - val_accur
Epoch 7/10
422/422 - 43s - loss: 0.0324 - accuracy: 0.9895 - val_loss: 0.0308 - val_accur
Epoch 8/10
422/422 - 44s - loss: 0.0278 - accuracy: 0.9909 - val_loss: 0.0261 - val_accur
Epoch 9/10
422/422 - 44s - loss: 0.0261 - accuracy: 0.9914 - val_loss: 0.0256 - val_accur
Epoch 10/10
422/422 - 43s - loss: 0.0239 - accuracy: 0.9920 - val_loss: 0.0211 - val_accur
Accuracy: 99.27999973297119
https://colab.research.google.com/drive/11c1QESByXTYVJLqxlDd1l5aSeY90ptfS#scrollTo=h0QAcvWmndrb Page 4 of 6
mnist2.ipynb - Colaboratory 27/06/23, 6:40 PM
image = x_train[5]
# lets display the image which we want to predict
plt.imshow(np.squeeze(image), cmap='gray')
plt.show()
OL
0
§ SZ
https://colab.research.google.com/drive/11c1QESByXTYVJLqxlDd1l5aSeY90ptfS#scrollTo=h0QAcvWmndrb Page 5 of 6
mnist2.ipynb - Colaboratory 27/06/23, 6:40 PM
0s completed at 6:06 PM
https://colab.research.google.com/drive/11c1QESByXTYVJLqxlDd1l5aSeY90ptfS#scrollTo=h0QAcvWmndrb Page 6 of 6