--- title: Cheque Dates Predictor LeNet5 emoji: 👁 colorFrom: pink colorTo: purple sdk: gradio sdk_version: 5.44.0 app_file: app.py pinned: false license: apache-2.0 short_description: Cheque Dates Predictor using LeNet5 CNN architecture --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference # Cheque Dates Predictor using LeNet5 ## Overview This project implements a system for extracting and recognizing handwritten dates from cheque images using the LeNet5 Convolutional Neural Network (CNN) architecture. The application automatically locates the date field on a cheque image, segments it into individual digits, and uses a trained CNN model to predict each digit, ultimately reconstructing the complete date in DD/MM/YYYY format. ## Features - Automatic extraction of date fields from cheque images - Segmentation of date into individual digits (day, month, year) - Digit recognition using LeNet5 CNN architecture - Interactive web interface built with Gradio - Visual feedback showing each step of the process - Complete date reconstruction in standard format ## Model Architecture The project uses the LeNet5 CNN architecture, which consists of: - Two convolutional layers with ReLU activation and average pooling - Three fully connected layers - Input size of 28x28 grayscale images - Output of 10 classes (digits 0-9) The architecture implementation: ```python class LeNet5(nn.Module): def __init__(self): super(LeNet5, self).__init__() self.conv1 = nn.Conv2d(1, 6, kernel_size=5, stride=1, padding=2) self.relu = nn.ReLU() self.pool = nn.AvgPool2d(kernel_size=2, stride=2) self.conv2 = nn.Conv2d(6, 16, kernel_size=5, stride=1) self.fc1 = nn.Linear(16 * 5 * 5, 120) self.fc2 = nn.Linear(120, 84) self.fc3 = nn.Linear(84, 10) def forward(self, x): x = self.pool(self.relu(self.conv1(x))) x = self.pool(self.relu(self.conv2(x))) x = x.view(-1, 16 * 5 * 5) x = self.relu(self.fc1(x)) x = self.relu(self.fc2(x)) x = self.fc3(x) return x ``` ## Installation ```bash # Clone the repository git clone https://github.com/yourusername/Cheque_Dates_Predictor_LeNet5.git cd Cheque_Dates_Predictor_LeNet5 # Install dependencies pip install -r requirements.txt ``` ## Dependencies The project requires the following Python packages: ``` gradio torch torchvision opencv-python pillow ``` ## Usage Run the application with: ```bash python app.py ``` The web interface will allow you to: 1. Upload a cheque image 2. View the extracted date region 3. See individual digit predictions 4. Get the complete predicted date ## How It Works The application follows these steps to extract and predict dates from cheque images: 1. **Image Preprocessing**: - The uploaded cheque image is converted to grayscale - The image is inverted (255 - pixel value) to enhance digit visibility 2. **Date Region Extraction**: - The system crops the date region using predefined coordinates (x=1790, y=100, width=460, height=80) - This region typically contains the handwritten date on standard cheque formats 3. **Digit Segmentation**: - Individual digits are extracted from the date region - The system segments the date into 8 parts: 2 for day (D1, D2), 2 for month (M1, M2), and 4 for year (Y1, Y2, Y3, Y4) - Each digit is saved as a separate image for processing 4. **Digit Recognition**: - Each digit image is preprocessed (resized to 28x28, normalized) - The LeNet5 CNN model predicts the digit value (0-9) 5. **Date Reconstruction**: - Individual digit predictions are combined to form the complete date in DD/MM/YYYY format ## Training The LeNet5 model was trained on the MNIST dataset, which contains 60,000 training images and 10,000 test images of handwritten digits. The training process included: - Data preprocessing with normalization - Model training with Adam optimizer and CrossEntropyLoss - Validation on a separate dataset to prevent overfitting - Testing on unseen data to evaluate performance The model achieved high accuracy on digit recognition tasks, making it suitable for cheque date extraction. ## Demo This project is deployed as a Hugging Face Space, providing an interactive demo where users can upload their own cheque images and see the date prediction in action. The demo includes: - An upload interface for cheque images - Display of the original and processed images - Visualization of each extracted digit - The final predicted date in DD/MM/YYYY format ## License This project is licensed under the Apache 2.0 License - see the LICENSE file for details.