Table of Contents
Digit.Recog.mp4
This project deals with the very popular learning process called
Deep learning using Neural Networks. There are various ways by which one can achieve the goal to a desired output, but in machine learning Neural network gives a way that machine learns the way to reach the output by creating human brain like structures i.e. 'NEURONS'.
In this given project we were required to make a full-stack application backed by a Deep Learning Model to predict the handwritten digit.
The goal was to create an appropriate model that can give the output of the handwritten character by drawing that character. This project has to be created by image processing and the machine learning. Both the techniques will be needed because these two techniques will enhance the technique of the machine learning and that can shape this project.
Neural Network and Deep Learning are the trending topics for now. And this is a simple project for handwriting recognition. The extension of the project can be used in large scale to detect the written character from images and to extract them in no time.Or in banking signature recognition or in license plate verification, Real time image chaining or filtering or object detection etc.
The MNIST dataset (Modified National Institute of Standards and Technology) is used. It is widely used for training and testing in the field of machine learning. It was created by "re-mixing" the samples from NIST's original datasets. The black and white images from NIST were normalized to fit into a 28x28 pixel bounding box with grayscale color channel.
- CNN is used.
- [[Conv2D->relu]2 -> MaxPool2D -> Dropout]2 -> Flatten -> Dense -> Dropout -> Out
- Optimizer : RMSprop -> Root Mean Squared Propagation
- Loss Function : categorical_crossentropy -> Used in multi-class classification model
- Learning Rate Annealer : ReduceLROnPlateau -> Reduce learning rate when a metric has stopped improving
- Metric : accuracy
- Model: "sequential"
Layer (type) | Output Shape | Param | |
---|---|---|---|
conv2d (Conv2D) | (None, 28, 28, 32) | 832 | |
conv2d_1 (Conv2D) | (None, 28, 28, 32) | 25632 | |
max_pooling2d (MaxPooling2D) | (None, 14, 14, 32) | 0 | |
dropout (Dropout) | (None, 14, 14, 32) | 0 | |
conv2d_2 (Conv2D) | (None, 14, 14, 64) | 18496 | |
conv2d_3 (Conv2D) | (None, 14, 14, 64) | 36928 | |
max_pooling2d_1 (MaxPooling 2D) | (None, 7, 7, 64) | 0 | |
dropout_1 (Dropout) | (None, 7, 7, 64) | 0 | |
flatten (Flatten) | (None, 3136) | 0 | |
dense (Dense) | (None, 256) | 803072 | |
dropout_2 (Dropout) | (None, 256) | 0 | |
dense_1 (Dense) | (None, 10) | 2570 |
Total params: 887,530
Trainable params: 887,530
Non-trainable params: 0
- Time Elapsed: 00:05:12.63
- Training Accuracy : 0.9887
- Validation Accuracy : 0.991
In order to avoid overfitting problem, we need to expand artificially our handwritten digit dataset. We can make your existing dataset even larger. The idea is to alter the training data with small transformations to reproduce the variations occuring when someone is writing a digit.
datagen = ImageDataGenerator(
featurewise_center=False, # set input mean to 0 over the dataset
samplewise_center=False, # set each sample mean to 0
featurewise_std_normalization=False, # divide inputs by std of the dataset
samplewise_std_normalization=False, # divide each input by its std
zca_whitening=False, # apply ZCA whitening
rotation_range=10, # randomly rotate images in the range (degrees, 0 to 180)
zoom_range = 0.1, # Randomly zoom image
width_shift_range=0.1, # randomly shift images horizontally (fraction of total width)
height_shift_range=0.1, # randomly shift images vertically (fraction of total height)
horizontal_flip=False, # randomly flip images
vertical_flip=False, # randomly flip images
fill_mode='nearest')
- Time Elapsed: 00:15:11.24
- Training Accuracy : 0.9850
- Validation Accuracy : 0.991
- To save whole model configuration + weights
model.save('digit_recognition.h5')
- To save the architecture of a model
model_json = model.to_json() with open("digit_recognition_config.json","w") as json_file: json_file.write(model_json)
- To save model with .tflite extension
converter = tf.lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert() with open('digit_recognition.tflite', 'wb') as tfliteFile: tfliteFile.write(tflite_model)
- To save model with tensorflowjs
import tensorflowjs as tfjs tfjs.converters.save_keras_model(model,".")
Well, this is the last part of this repository. Here are the list of links which helped me to build this whole project, the android one and the web one.