A deep learning-based signature verification system that uses a Siamese Neural Network to compare two handwritten signatures and determine whether they are genuine or potentially forged.
The project uses contrastive loss to learn signature similarity, Euclidean distance to compare signature embeddings, and a validation-based threshold for verification.
Handwritten signature verification is an important biometric authentication technique used to verify identity in documents and financial transactions.
This project implements a signature verification system using a Siamese Convolutional Neural Network (CNN). Instead of classifying a single signature independently, the model learns to compare two signature images and measure how similar they are.
The system takes two signature images as input:
- Reference Signature: A known genuine signature.
- Questioned Signature: A signature that needs to be verified.
The model generates embeddings for both images and calculates their Euclidean distance. A threshold selected using validation data is then used to classify the pair as genuine or forged.
- Siamese CNN architecture for signature verification.
- Contrastive loss for learning signature similarity.
- Image preprocessing using OpenCV.
- Writer-level training, validation, and testing splits.
- Genuine-genuine and genuine-forged signature pair generation.
- Euclidean distance-based verification.
- Validation-based threshold selection.
- Performance evaluation using classification metrics.
- Confusion matrix and ROC curve generation.
- Interactive Streamlit application for signature comparison.
| Category | Technologies |
|---|---|
| Programming Language | Python |
| Deep Learning | TensorFlow, Keras |
| Image Processing | OpenCV, Pillow |
| Data Handling | NumPy |
| Machine Learning Evaluation | Scikit-learn |
| Visualization | Matplotlib, Seaborn |
| Web Application | Streamlit |
This project uses the CEDAR Signature Dataset, which contains genuine and forged handwritten signature samples from multiple writers.
Dataset source:
CEDAR Signature Dataset – Kaggle
Download the dataset and arrange the folders according to the following structure:
dataset/
└── CEDAR/
├── full_org/
└── full_forg/
full_org/contains genuine signature images.full_forg/contains forged signature images.
Note: The dataset is not included in this repository. Download it separately and place it in the specified directory before training or evaluation.
The project uses a Siamese Convolutional Neural Network consisting of two identical branches that share the same weights.
Each branch processes one signature image and generates a 128-dimensional feature embedding.
- Input Layer: Accepts grayscale signature images of size 155 × 220 × 1.
- Convolutional Layers: Four convolutional layers with 32, 64, 128, and 256 filters extract visual features.
- Batch Normalization: Helps stabilize training.
- Max Pooling: Reduces spatial dimensions while retaining important features.
- Global Average Pooling: Converts feature maps into a compact feature representation.
- Fully Connected Layers: A 256-unit dense layer with ReLU activation and dropout learns higher-level representations.
- Embedding Layer: Generates a normalized 128-dimensional embedding.
The two embeddings are compared using Euclidean distance.
The model is trained using Contrastive Loss, which encourages similar signature pairs to have smaller distances and dissimilar pairs to have larger distances.
The loss function implemented in the project is:
Where:
- (y) represents the pair label.
- (D) represents the Euclidean distance between embeddings.
- (m) represents the margin.
In this project:
- Label
1represents a genuine pair. - Label
0represents a forged pair. - The margin is set to
1.0.
Before being passed to the model, signature images undergo the following preprocessing steps:
- Convert the image into grayscale.
- Apply Otsu's thresholding for foreground extraction.
- Crop the signature to remove unnecessary background regions.
- Resize the signature while maintaining its aspect ratio.
- Place the resized signature on a white canvas.
- Normalize pixel values between 0 and 1.
- Reshape the image into the required input dimensions.
Final image dimensions:
155 × 220 × 1
The following configuration parameters are used for model training:
| Parameter | Value |
|---|---|
| Image Height | 155 |
| Image Width | 220 |
| Channels | 1 |
| Batch Size | 32 |
| Epochs | 10 |
| Learning Rate | 0.0001 |
| Embedding Dimension | 128 |
| Contrastive Loss Margin | 1.0 |
| Random State | 42 |
The dataset is divided at the writer level to prevent signatures belonging to the same writer from appearing across different data splits.
| Split | Proportion |
|---|---|
| Training | 80% |
| Validation | 10% |
| Testing | 10% |
Genuine-genuine pairs and genuine-forged pairs are generated separately for each split, with up to 30 pairs per class for each writer.
The training process uses:
- Early Stopping: Monitors validation loss and restores the best weights.
- ReduceLROnPlateau: Reduces the learning rate when validation loss stops improving.
- Model Checkpointing: Saves the best-performing model during training.
The model is evaluated using a separate test set after selecting the verification threshold using validation data.
The following evaluation metrics are calculated:
- Accuracy
- Precision
- Recall
- F1-Score
- ROC-AUC
The project also generates:
- Confusion Matrix
- ROC Curve
- Evaluation Metrics in JSON format
The evaluation script saves the generated results inside the outputs/ directory.
The verification threshold is selected by optimizing the F1-score on the validation set, with accuracy used as a tie-breaker. The selected threshold is then applied to the test set.
- The model is trained and evaluated using a limited number of signature pairs generated from the CEDAR dataset.
- The number of pairs is controlled by the pair-generation configuration, which allows up to 30 genuine and 30 forged pairs per writer.
- The reported evaluation metrics reflect performance on the specific dataset and writer-level splits used in this project.
- A high test accuracy, including 100% if achieved, should not be interpreted as a guarantee of equivalent performance on completely unseen datasets or real-world signatures.
- Further testing on independent datasets and more diverse signature samples would be required to establish broader generalization.
git clone https://github.com/simratkaur210555/Signature-Forgery-Detection-Using-Deep-learning.gitcd Signature-Forgery-Detection-Using-Deep-learningpython -m venv venvActivate it:
Windows:
venv\Scripts\activatemacOS/Linux:
source venv/bin/activatepip install -r requirements.txtDownload the CEDAR Signature Dataset and place its full_org and full_forg folders inside:
dataset/CEDAR/
Run the following command from the project root directory:
python -m src.trainThis generates signature pairs, preprocesses the images, trains the Siamese CNN, and saves the model.
python -m src.evaluationThis evaluates the trained model, determines the optimal verification threshold using validation data, and generates the evaluation metrics and visualizations.
streamlit run app.pyThe application opens in your browser.
- Launch the Streamlit application.
- Upload a genuine reference signature.
- Upload the questioned signature.
- Click the verification button.
- The application preprocesses both images and compares their learned embeddings.
- The result is displayed as either GENUINE or FORGED, along with the calculated distance and verification threshold.
A smaller Euclidean distance indicates greater similarity between the two signature representations.
| File | Description |
|---|---|
app.py |
Streamlit interface for signature verification. |
src/config.py |
Stores project paths and model configuration parameters. |
src/dataset.py |
Loads signature images, generates pairs, and creates dataset splits. |
src/preprocessing.py |
Performs image preprocessing and normalization. |
src/model.py |
Defines the Siamese CNN and contrastive loss function. |
src/train.py |
Handles model training and checkpointing. |
src/evaluation.py |
Calculates evaluation metrics and generates visualizations. |
src/predict.py |
Handles signature comparison and verification predictions. |
- The model depends on the quality and consistency of uploaded signature images.
- Performance may vary with differences in image resolution, scanning conditions, and signature appearance.
- The system evaluates static signature images and does not analyze dynamic handwriting information such as pen pressure, writing speed, or pen movement.
- A genuine prediction indicates similarity according to the trained model and does not establish the legal authenticity of a signature.
This project is intended for educational and experimental purposes. It should not be treated as a certified forensic verification system or a substitute for professional examination.
- Experiment with more advanced Siamese and metric-learning architectures.
- Improve generalization across different signature datasets.
- Explore additional image augmentation techniques.
- Evaluate performance under different image quality conditions.
- Develop a more comprehensive signature verification interface.
Simrat Kaur
B.Tech Computer Science and Engineering (AI & ML)
If you find this project useful, consider giving the repository a ⭐.

