File size: 2,145 Bytes
4842b15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91a6671
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
license: mit
datasets:
- ylecun/mnist
language:
- en
metrics:
- f1
- precision
- recall
- accuracy
tags:
- pattern-recognition
- mnist
- image-classification
---
# MNIST Pattern Recognition with Convolutional Neural Network (CNN)

This project implements a Convolutional Neural Network (CNN) for recognizing handwritten digits from the MNIST dataset. The model is built using TensorFlow and Keras, and it supports both single-GPU and multi-GPU training. The project includes training, testing, and a user-friendly GUI for inference.

## Features
- **Customizable CNN Architecture**: Includes convolutional, pooling, normalization, and dense layers.
- **Multi-GPU Support**: Leverages TensorFlow's `MirroredStrategy` for distributed training.
- **Training Visualization**: Generates plots for training/validation accuracy and loss.
- **Evaluation Metrics**: Outputs confusion matrix, classification report, and precision/recall/F1 scores.
- **Interactive GUI**: Built with Streamlit for real-time image recognition.
- **Docker Support**: Easily deployable using Docker.

## Model Architecture
![image](model.png) <br>
The CNN model consists of:
1. Two convolutional layers with ReLU activation and max-pooling.
2. Layer normalization for improved convergence.
3. Fully connected dense layers with dropout for regularization.
4. Softmax output layer for classification into 10 digit classes.

## Training
The model is trained on the MNIST dataset, which contains 60,000 training images and 10,000 test images of handwritten digits (28x28 grayscale). The training process includes:
- Data normalization to scale pixel values to the range [0, 1].
- Categorical cross-entropy loss and accuracy as the evaluation metric.
- Model checkpointing to save the best-performing model based on validation accuracy.

## Final result
**Training history**
![image](training_history.png) <br>

**Confusion matrix**
![image](confusion_matrix.png) <br>

**Classification report**
![image](classification_report_image.png) <br>

**Test result**
![image](test_result.png) <br>

Full code at [Github](https://github.com/longdnk/Pattern-Recognition/tree/main/MNIST)