Skip to content

Commit c155202

Browse files
Merge pull request avinashkranjan#1577 from Raghucharan16/master
Hand-Written-Digit-Recognition
2 parents 2187b62 + 6fb7970 commit c155202

File tree

13 files changed

+496
-0
lines changed

13 files changed

+496
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Hand-Written-Digit-Recognition
2+
3+
This project is a demonstration of a Hand Written Digit Recognition system. It uses machine learning techniques to recognize and classify handwritten digits.
4+
Fed and trained on MNIST dataset using 5 layer convolution neural network.
5+
6+
The project is hosted on GitHub Pages and can be accessed at https://raghucharan16.github.io/Hand-Written-Digit-Recognition/.
7+
8+
# Features
9+
* Handwritten digit recognition: The system can recognize and classify handwritten digits ranging from 0 to 9.
10+
* Web interface: Users can draw digits on the web canvas provided by the application.
11+
* Real-time prediction: The application provides real-time predictions as the user draws the digit.
12+
* Clear functionality: Users can clear the canvas to start a new drawing.
13+
* Model details: The repository includes the trained model used for digit recognition.
14+
15+
# Usage
16+
To use the Hand Written Digit Recognition system, follow these steps:
17+
18+
* Open the web application using the provided link: https://raghucharan16.github.io/Hand-Written-Digit-Recognition/.
19+
* Once the application is loaded, you will see a canvas on which you can draw digits using your mouse or touch input.
20+
* Draw a digit on the canvas. As you draw, the application will display real-time predictions for the digit you are drawing.
21+
* If you want to start a new drawing, click the "Clear" button to clear the canvas and predictions.
22+
* Repeat steps 3-4 as desired.
23+
24+
# Development
25+
If you are interested in contributing to this project or running it locally, follow these instructions:
26+
27+
Clone the repository: git clone https://github.com/raghucharan16/Hand-Written-Digit-Recognition.git
28+
Navigate to the project directory: cd Hand-Written-Digit-Recognition
29+
Open the index.html file in a web browser to access the application locally.
30+
31+
# Dependencies
32+
The Hand Written Digit Recognition project relies on the following dependencies:
33+
34+
* HTML5 Canvas: Used for drawing and capturing user input.
35+
* TensorFlow.js: A JavaScript library for machine learning used for the digit recognition model(tensorflowjs works only when tensorflow version <1.6).
36+
* Bootstrap: A CSS framework used for styling and layout.
37+
* jQuery: A JavaScript library used for DOM manipulation and event handling.
38+
* The required dependencies are already included in the project repository, so there is no need for additional setup.
39+
40+
## Demo
41+
![handwritten-recognition-5](https://github.com/Raghucharan16/Amazing-Python-Scripts/assets/104614903/872abeb1-5e44-496c-a166-b9f25e2f7acd)
42+
43+
44+
Contact
45+
If you have any questions, suggestions, ideas or issues regarding the project, please feel free to contact the me.
46+
47+
GitHub: [Raghucharan16](https://github.com/Raghucharan16)
48+
49+
**Your feedback and contributions are most welcome!!**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
python==3.6
2+
tensorflow==2.1
3+
tensorflowjs==3.1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import tensorflow as tf
2+
import tensorflowjs as tfjs
3+
from tensorflow import keras
4+
5+
# load the data
6+
(train_img,train_label),(test_img,test_label) = keras.datasets.mnist.load_data()
7+
train_img = train_img.reshape([-1, 28, 28, 1])
8+
test_img = test_img.reshape([-1, 28, 28, 1])
9+
train_img = train_img/255.0
10+
test_img = test_img/255.0
11+
train_label = keras.utils.to_categorical(train_label)
12+
test_label = keras.utils.to_categorical(test_label)
13+
14+
# define the model architecture
15+
model = keras.Sequential([
16+
keras.layers.Conv2D(32, (5, 5), padding="same", input_shape=[28, 28, 1]),
17+
keras.layers.MaxPool2D((2,2)),
18+
keras.layers.Conv2D(64, (5, 5), padding="same"),
19+
keras.layers.MaxPool2D((2,2)),
20+
keras.layers.Flatten(),
21+
keras.layers.Dense(1024, activation='relu'),
22+
keras.layers.Dropout(0.2),
23+
keras.layers.Dense(10, activation='softmax')
24+
])
25+
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
26+
27+
# train the model
28+
model.fit(train_img,train_label, validation_data=(test_img,test_label), epochs=10)
29+
test_loss,test_acc = model.evaluate(test_img, test_label)
30+
print('Test accuracy:', test_acc)
31+
32+
# save model as tfjs format
33+
tfjs.converters.save_keras_model(model, 'models')
76.8 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset='utf-8'>
5+
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
6+
<meta name='viewport' content='width=device-width, initial-scale=1'>
7+
<title>Hand Written Digit Recognition using TensorFlow.js</title>
8+
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
9+
<script src="js/chart.min.js"></script>
10+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
11+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
12+
<link rel="stylesheet" type="text/css" href="style/digit.css">
13+
</head>
14+
<body>
15+
<main>
16+
<div class="container mt-1">
17+
<div class="digit-demo-container">
18+
<h3>Hand Written Digit Recognition</h3>
19+
<div class="flex-two">
20+
<div id="canvas_box_wrapper" class="canvas-box-wrapper">
21+
<div id="canvas_box" class="canvas-box"></div>
22+
<div class="col-12">
23+
<button id="clear-button" class="btn btn-dark">Clear</button>
24+
</div>
25+
<div class="col-12">
26+
<button id="predict-button" class="btn btn-dark">Predict</button>
27+
</div>
28+
</div>
29+
<div class="col-6">
30+
<div id="result_box" class="col-12 col-md-7">
31+
<canvas id="chart_box" width="100" height="100"></canvas>
32+
</div>
33+
<div class="col-12 d-block mt-2 mt-md-0 text-md-left prediction-text"></div>
34+
</div>
35+
</div>
36+
</div>
37+
</div>
38+
</main>
39+
40+
<script src="js/digit-recognition.js"></script>
41+
</body>
42+
</html>

Hand-Written-Digit-Recognition/js/chart.min.js

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)