Coders Packet

Hand-Written-Digit-Recognition-using_CNN MODEL-(Python)

By Kunjesh Mahajan

In this project, I use the CNN method to recognize the handwritten digits provided by the user.

Convolutional Neural Network  - It is a class of deep neural networks. 

Below is the procedure to make the mnist model.

MNIST handwritten digit classification problem is a standard dataset used in computer vision and deep learning.

train - test - split

(X_train, y_train), (X_test, y_test) = dataset.load_data()

normalize value to b/w 0and1

X_train= X_train/255.0
X_test= X_test/255.0

CNN (BATCH, HEIGHT, WIDTH, 1)

ANN (BATCH_SIZE, FEATURES)

FEATURES = WIDTH * HEIGHT

reshape array to fit in the network.

X_train = X_train.reshape(X_train.shape[0], -1)
X_test = X_test.reshape(X_test.shape[0], -1)

(batch_size, height, width, 1)

ANN

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout

0-1

model = Sequential()
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.2))

model.add(Dense(128, activation='relu'))
model.add(Dropout(0.2))

0-9

model.add(Dense(10, activation='softmax'))

model.compile('adam', 'sparse_categorical_crossentropy', metrics=['acc'])

model.fit(X_train, y_train, epochs=3, batch_size=12, validation_split=0.1)

making prediction

plt.imshow(X_test[1255].reshape(28,28), cmap='gray')
plt.xlabel(y_test[1255])
plt.ylabel(np.argmax(model.predict(X_test)[1255]))


model.save('digit_trained.h5')

The model is ready.

prediction via paints.

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Kunjesh Mahajan (kunmva)

Download packets of source code on Coders Packet