Import As Import As Import Import As Import As From Import From Import From Import From Import From Import From Import
Import As Import As Import Import As Import As From Import From Import From Import From Import From Import From Import
Import As Import As Import Import As Import As From Import From Import From Import From Import From Import From Import
import pandas as pd
import random
import tensorflow as tf
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score
print(X_train.shape)
X_train[0].min(), X_train[0].max()
(0, 255)
(0.0, 1.0)
array([5, 0, 4, 1, 9, 2, 1, 3, 1, 4, 3, 5, 3, 6, 1, 7, 2, 8, 6, 9],
dtype=uint8)
model = Sequential([
Conv2D(32, (3, 3), activation="relu", input_shape=(28, 28, 1)),
MaxPooling2D((2, 2)),
Flatten(),
Dense(100, activation="relu"),
Dense(10, activation="softmax")
])
WARNING:tensorflow:From C:\Users\rutik\anaconda3\Lib\site-packages\keras\src\layers\pooling\max_pooling2d.py:161
: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 26, 26, 32) 320
=================================================================
Total params: 542230 (2.07 MB)
Trainable params: 542230 (2.07 MB)
Non-trainable params: 0 (0.00 Byte)
_________________________________________________________________
Epoch 1/10
WARNING:tensorflow:From C:\Users\rutik\anaconda3\Lib\site-packages\keras\src\utils\tf_utils.py:492: The name tf.
ragged.RaggedTensorValue is deprecated. Please use tf.compat.v1.ragged.RaggedTensorValue instead.
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()
n=random.randint(0,9999)
plt.imshow(X_test[n])
plt.show()
predicted_value=model.predict(X_test)
print("Handwritten number in the image is= %d" %np.argmax(predicted_value[n]))