Arcus72 commited on
Commit
c987302
·
verified ·
1 Parent(s): 986aeee

Add files

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. README.md +34 -13
  3. app.py +57 -0
  4. requirements.txt +0 -0
  5. saved_model.keras +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ saved_model.keras filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,34 @@
1
- ---
2
- title: Image Digit Classification
3
- emoji: 📉
4
- colorFrom: yellow
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 6.6.0
8
- app_file: app.py
9
- pinned: false
10
- short_description: This project is a machine learning application designed to r
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Digit Classification System
2
+ This project is a machine learning application designed to recognize handwritten digits using Convolutional Neural
3
+ Networks (CNN). It includes tools for data preprocessing, model training, and an interactive drawing interface for real-time predictions.
4
+
5
+ 👉 [Live Demo](https://huggingface.co/spaces/Arcus72/Image-Digit-Classification)
6
+
7
+ ## Files
8
+ - **app.py**: The main application file that creates a Gradio interface for the digit recognition system.
9
+ - **main_analysis.ipynb**: A Jupyter notebook that contains the data processing, model training, and evaluation code.
10
+ - **train_mnist.csv**: The dataset used for training the model.
11
+
12
+ ## Data source
13
+ - **Source**: [MNIST in CSV (Kaggle)](https://www.kaggle.com/datasets/oddrationale/mnist-in-csv)
14
+ - **Format**: CSV containing grayscale pixel values (0–255).
15
+ - **Target**: The label column representing the digit (0–9).
16
+ - **Dimensions**: Aside from the label, each row consists of 784 features (a flattened 28×28 pixel image).
17
+
18
+ ## Key Features
19
+ - **Data processing for model training**: Processes raw CSV data into $28 \times 28$ grayscale images by parsing pixel
20
+ coordinates (from train_mnist.csv).
21
+ - **Dynamic Data Augmentation (new)**: Enhances model generalization using random rotations, translations, and zooms.
22
+ - **Automated Hyperparameter Tuning (new)**: Utilizes BayesianOptimization to search for the best architecture, including the number of layers, filters, dropout rates, and optimizers.
23
+ - **Comprehensive Evaluation**: Features detailed visualization of label distribution, confusion matrices, and an analysis of misclassified samples.
24
+ - **Interactive Demo**: A Gradio interface that allows users to draw digits and get instant predictions from the trained model.
25
+
26
+ ## Tech Stack
27
+ - **Core**: Python, TensorFlow/Keras
28
+ - **Tuning**: Keras Tuner
29
+ - **Data Science**: Pandas, NumPy, Scikit-learn
30
+ - **Visualization**: Matplotlib, Tkinter, Pillow (PIL)
31
+ - **UI**: Gradio
32
+
33
+ ## Results
34
+ Based on the tuning process, the model typically achieves **>98%** accuracy on the test set.
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
3
+
4
+ import numpy as np
5
+ import gradio as gr
6
+ from tensorflow.keras.models import load_model
7
+ model = load_model('saved_model.keras')
8
+
9
+ def predict_number(image):
10
+
11
+ image_rgb = image["composite"][..., :3] # delete alpha
12
+ image_grayScale= np.mean(image_rgb, axis=-1).astype(np.uint8)
13
+
14
+ image_grayScale = image_grayScale.reshape(1, 280, 280, 1)
15
+ print(image_grayScale)
16
+ preds = model.predict(image_grayScale)[0]
17
+
18
+ return {str(i): float(preds[i]) for i in range(10)}
19
+
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown("""
22
+ <center>
23
+ <h1>Digit Classification</h1>
24
+ </center>
25
+
26
+ ## How to use:
27
+ 1. **Draw a single digit** (0-9) in the center of the black canvas. Digit should be as large as possible.
28
+ 2. **Click 'Recognize'** to see the prediction and the model's confidence levels.
29
+ 3. **Click 'Clear canvas'** to clear the canvas.
30
+
31
+ """)
32
+ sketch_pad = gr.Sketchpad(
33
+ label="Draw here (White on Black)",
34
+ layers=False,
35
+ canvas_size=(280, 280),
36
+ brush=gr.Brush(colors=["#FFFFFF"], default_color="#FFFFFF", default_size=10),
37
+ value={
38
+ "background": np.zeros((280, 280, 3), dtype=np.uint8),
39
+ "layers": [],
40
+ "composite": None
41
+ },
42
+ type="numpy"
43
+ )
44
+
45
+ btn = gr.Button("Recognize", variant="primary")
46
+ clear_btn = gr.Button("Clear canvas", variant="stop")
47
+ output = gr.Label(num_top_classes=3, label="Prediction")
48
+
49
+ clear_btn.click(lambda: {"background": np.zeros((280, 280, 3), dtype=np.uint8), "layers": [], "composite": None},
50
+ outputs=sketch_pad)
51
+ btn.click(predict_number, inputs=sketch_pad, outputs=output)
52
+ gr.Markdown("""
53
+ ## GitHub Repository
54
+ If you want to see the training process, data augmentation, and how the model was built,
55
+ check out the **[main_analysis.ipynb](https://github.com/Arcus72/Image-Digit-Classification)** file in my GitHub repository.""")
56
+
57
+ demo.launch(theme=gr.themes.Soft())
requirements.txt ADDED
Binary file (6.17 kB). View file
 
saved_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a0b7b9c0fb635c4dd8d0cbcbcb209cef9b17eaa9bba3579586828482d94a0ba
3
+ size 6964085