A comprehensive deep learning project for Indian Sign Language (ASL) alphabet recognition, featuring three state-of-the-art CNN architectures with attention mechanisms for improved accuracy and generalization.
- Overview
- Models
- Features
- Installation
- Dataset Structure
- Usage
- Model Performance
- Results
- Project Structure
- Contributing
- License
- Acknowledgments
This project implements three progressively advanced CNN architectures for sign language alphabet recognition (A-Z), demonstrating the impact of attention mechanisms on model performance:
- Base CNN: Standard convolutional neural network with batch normalization
- CNN + SE Blocks: Enhanced with Squeeze-and-Excitation blocks for channel attention
- CNN + SE + CBAM: Advanced model combining SE blocks with Convolutional Block Attention Module
- β Three model architectures with increasing complexity
- β Complete training and inference pipelines
- β Real-time webcam prediction support
- β Batch processing capabilities
- β Interactive visualizations
- β Comprehensive performance analysis tools
Architecture: 4 convolutional blocks with batch normalization and max pooling
Conv(32) β BN β Pool β Conv(64) β BN β Pool β
Conv(128) β BN β Pool β Conv(256) β BN β Pool β
FC(512) β Dropout β FC(256) β Dropout β FC(26)
Features:
- Standard CNN architecture
- Batch normalization for stable training
- Dropout regularization (0.2)
- Baseline performance reference
Files: BaseCNNModel.py, Base_inference.py, Base_tester.py
Architecture: Base CNN + Squeeze-and-Excitation blocks after each conv layer
[Conv(32) β BN β SE] β Pool β [Conv(64) β BN β SE] β Pool β
[Conv(128) β BN β SE] β Pool β [Conv(256) β BN β SE] β Pool β
FC(512) β Dropout β FC(256) β Dropout β FC(26)
SE Block Components:
- Global Average Pooling (Squeeze)
- Two FC layers with reduction ratio 16 (Excitation)
- Sigmoid activation for channel weighting
Improvements over Base CNN:
- π +2-3% validation accuracy
- π― Better feature channel prioritization
- πͺ Reduced overfitting
- π Improved discrimination of similar signs
Files: Base_SEBlock_Model.py, SE_inference.py, BaseSE_tester.py
Architecture: SE blocks in first 3 layers + CBAM in final layer
[Conv(32) β BN β SE] β Pool β [Conv(64) β BN β SE] β Pool β
[Conv(128) β BN β SE] β Pool β [Conv(256) β BN β CBAM] β Pool β
FC(512) β Dropout β FC(256) β Dropout β FC(26)
CBAM (Convolutional Block Attention Module):
- Channel Attention: Both average and max pooling features
- Spatial Attention: Focuses on important spatial locations
- Sequential refinement: Channel β Spatial attention
Improvements over CNN + SE:
- π Additional 1-2% accuracy gain
- πΊοΈ Spatial attention for better localization
- π― Enhanced robustness to hand position variations
- β‘ Dual attention mechanism (channel + spatial)
Files: Base_SE_CBAM_Model.py, SE_CBAM_inference.py, Base_SECbam_Tester.py
- β Data augmentation (rotation, flipping, color jittering, random erasing)
- β Label smoothing for better generalization
- β Learning rate scheduling (Cosine Annealing with Warm Restarts)
- β Early stopping with patience
- β Gradient clipping
- β Model checkpointing (saves best model)
- β Training history visualization
- πΌοΈ Single image prediction with top-K results
- π Batch processing with automatic accuracy calculation
- π₯ Real-time webcam prediction with FPS counter
- π Confusion matrix generation
- π Performance analysis and comparison
- πΎ Results export to CSV
- π¨ Beautiful visualizations
- Python 3.8 or higher
- CUDA-capable GPU (recommended) or CPU
- Webcam (optional, for real-time prediction)
- Clone the repository
git clone https://github.com/AdityaMohanty374/SignNet.git
cd SignNet- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txttorch>=2.0.0
torchvision>=0.15.0
numpy>=1.24.0
matplotlib>=3.7.0
seaborn>=0.12.0
scikit-learn>=1.3.0
opencv-python>=4.8.0
Pillow>=10.0.0
tqdm>=4.65.0
pandas>=2.0.0
Organize your sign language dataset as follows:
dataset/
βββ A/
β βββ image_001.jpg
β βββ image_002.jpg
β βββ ...
βββ B/
β βββ image_001.jpg
β βββ ...
βββ C/
β βββ ...
...
βββ Z/
βββ ...
Dataset Requirements:
- 26 folders (A-Z)
- Images in JPG/PNG format
- Recommended: 200+ images per letter
- Image size: Any (will be resized to 224Γ224)
Popular Datasets:
- ISL Alphabet Dataset (Kaggle)
- Sign Language MNIST
python BaseCNNModel.pypython Base_SEBlock_Model.pypython Base_SE_CBAM_Model.pyTraining Configuration:
Edit the hyperparameters in the respective Base_*.py files:
NUM_CLASSES = 26
BATCH_SIZE = 32
NUM_EPOCHS = 100
LEARNING_RATE = 0.001
WEIGHT_DECAY = 5e-4
DROPOUT_RATE = 0.3Training Output:
best_sign_language_model.pth(Base CNN)best_se_sign_language_model.pth(SE model)best_se_cbam_sign_language_model.pth(SE+CBAM model)- Training history plots
- Confusion matrices
Base CNN:
from Base_inferece import SignLanguagePredictor
predictor = SignLanguagePredictor('best_sign_language_model.pth')
result = predictor.predict_image('test_image.jpg')
print(f"Predicted: {result['top_prediction']['letter']}")
print(f"Confidence: {result['top_prediction']['confidence']:.2f}%")
# With visualization
predictor.visualize_prediction('test_image.jpg', save_path='result.png')SE Model:
from SE_inference import SESignLanguagePredictor
predictor = SESignLanguagePredictor('best_se_sign_language_model.pth')
predictor.visualize_prediction('test_image.jpg')SE+CBAM Model:
from SE_CBAM_inference.py import SECBAMSignLanguagePredictor
predictor = SECBAMSignLanguagePredictor('best_se_cbam_sign_language_model.pth')
predictor.visualize_prediction('test_image.jpg')# Process entire folder
results = predictor.batch_predict('test_images/', output_csv='results.csv')
# Automatic accuracy calculation (if images named as: A_001.jpg, B_045.jpg, etc.)
# Output includes: filename, predicted_letter, confidence, true_label, correct# Start webcam prediction
predictor.predict_webcam(mirror=True, show_fps=True)
# Controls:
# - Press 'q' to quit
# - Press 's' to save current frame
# - Press 'r' to reset prediction# Compare model performance on test set
analysis = predictor.compare_with_baseline('test_images/')
print(f"Accuracy: {analysis['accuracy']:.2f}%")
print(f"Average Confidence: {analysis['avg_confidence']:.2f}%")| Model | Parameters | Val Accuracy | Training Time | Inference Speed |
|---|---|---|---|---|
| Base CNN | ~50M | 87-90% | ~2 hours | 30 FPS |
| CNN + SE | ~52M (+4%) | 89-93% | ~2.5 hours | 28 FPS |
| CNN + SE + CBAM | ~53M (+6%) | 91-95% | ~3 hours | 26 FPS |
Tested on NVIDIA Tesla T4, batch size 32, 100 epochs
CNN + SE vs Base CNN:
- β +2-3% accuracy improvement
- β Better generalization (smaller train-val gap)
- β Improved feature channel selection
- β More robust to lighting variations
CNN + SE + CBAM vs CNN + SE:
- β +1-2% additional accuracy
- β Better spatial feature localization
- β Enhanced robustness to hand position
- β Improved discrimination of similar signs (M/N, K/V)
| Benefit | SE Blocks | CBAM |
|---|---|---|
| Channel Attention | β | β |
| Spatial Attention | β | β |
| Parameter Overhead | +2% | +3% |
| Accuracy Gain | +2-3% | +3-5% |
| Overfitting Reduction | β | β β |
The models show excellent performance across all letters, with occasional confusion between similar hand shapes:
Common Confusions:
- M β N (similar finger positions)
- K β V (similar hand orientations)
- A β S (closed fist variations)
CBAM Improvements: The spatial attention in CBAM significantly reduces these confusions by focusing on discriminative spatial features.
All models show:
- Smooth convergence with cosine annealing
- Reduced overfitting with attention mechanisms
- Stable validation performance
sign-language-recognition/
βββ README.md
βββ requirements.txt
βββ LICENSE
β
βββ Models/
β βββ BaseCNNModel.py # Base CNN model
β βββ Base_SEBlock_Model.py # CNN + SE model
β βββ Base_SE_CBAM_Model.py # CNN + SE + CBAM model
β
βββ Inference/
β βββ Base_inference.py # Base CNN inference
β βββ SE_inference.py # SE model inference
β |ββ SE_CBAM_inference.py # SE+CBAM inference
| βββ Testers/
| βββ BaseSE_tester.py
| βββ Base_SECbam_Tester.py
| βββ Base_tester.py
β
βββ checkpoints/
β βββ best_sign_language_model.pth
β βββ best_se_sign_language_model.pth
β βββ best_se_cbam_sign_language_model.pth
β
βββ results/
βββ training_history/
βββ confusion_matrices/
βββ predictions/
class SEBlock(nn.Module):
def __init__(self, channels, reduction=16):
super(SEBlock, self).__init__()
self.squeeze = nn.AdaptiveAvgPool2d(1)
self.excitation = nn.Sequential(
nn.Linear(channels, channels // reduction, bias=False),
nn.ReLU(inplace=True),
nn.Linear(channels // reduction, channels, bias=False),
nn.Sigmoid()
)
def forward(self, x):
b, c, _, _ = x.size()
# Squeeze: Global information embedding
y = self.squeeze(x).view(b, c)
# Excitation: Adaptive recalibration
y = self.excitation(y).view(b, c, 1, 1)
# Scale: Channel-wise multiplication
return x * y.expand_as(x)class CBAM(nn.Module):
def __init__(self, channels, reduction=16, kernel_size=7):
super(CBAM, self).__init__()
# Channel Attention
self.mlp = nn.Sequential(
nn.Linear(channels, channels // reduction, bias=False),
nn.ReLU(inplace=True),
nn.Linear(channels // reduction, channels, bias=False)
)
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.sigmoid_channel = nn.Sigmoid()
# Spatial Attention
self.conv_spatial = nn.Conv2d(2, 1, kernel_size, stride=1,
padding=kernel_size // 2, bias=False)
self.sigmoid_spatial = nn.Sigmoid()
def forward(self, x):
b, c, _, _ = x.size()
# ---- Channel Attention ----
avg_out = self.mlp(self.avg_pool(x).view(b, c))
max_out = self.mlp(self.max_pool(x).view(b, c))
channel_att = self.sigmoid_channel(avg_out + max_out).view(b, c, 1, 1)
x = x * channel_att.expand_as(x)
# ---- Spatial Attention ----
avg_out = torch.mean(x, dim=1, keepdim=True)
max_out, _ = torch.max(x, dim=1, keepdim=True)
spatial_att = self.sigmoid_spatial(self.conv_spatial(torch.cat([avg_out, max_out], dim=1)))
x = x * spatial_att.expand_as(x)
return xContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- π New attention mechanisms (ECA, CBAM variants)
- π Additional datasets and benchmarks
- π Model optimization (pruning, quantization)
- π Web/mobile deployment
- π± Mobile-optimized models
- π₯ Video sequence recognition
# Clone repo
git clone https://github.com/AdityaMohanty374/SignNet.git
# Create branch
git checkout -b feature/your-feature
# Make changes and commit
git commit -m "Add your feature"
# Push and create PR
git push origin feature/your-featureThis project is licensed under the MIT License - see the LICENSE file for details.
-
Papers:
- Squeeze-and-Excitation Networks (Hu et al., 2018)
- CBAM: Convolutional Block Attention Module (Woo et al., 2018)
-
Datasets:
- Indian Sign Language Alphabet Dataset (Kaggle)
- Sign Language MNIST
-
Frameworks:
- PyTorch
- OpenCV
- Scikit-learn
- Author: Aditya Mohanty
- Email: mohantyaditya589@gmail.com
- GitHub: @AdityaMohanty374
If you find this project helpful, please consider giving it a star β!
If you use this code in your research, please cite:
@software{sign_language_recognition_2024,
author = {Aditya Mohanty},
title = {SignNet-Sign Language Recognition with Attention Mechanisms},
year = {2024},
url = {https://github.com/AdityaMohanty374/SignNet}
}Made with β€οΈ for the deaf and hard-of-hearing community
β Star this repo if you find it helpful!



