Trained on 2000+ labeled images for superior accuracy
- Features
- Demo
- Installation
- Quick Start
- API Documentation
- Model Architecture
- Training
- Usage Examples
- Performance
- Project Structure
- Contributing
- License
- Author
- π― High Accuracy: 95%+ success rate on CAPTCHA recognition
- β‘ Fast Processing: ~100ms per CAPTCHA solve
- π REST API: FastAPI-based with full Swagger documentation
- π§ Deep Learning: CNN + BiLSTM architecture with CTC loss
- π¦ Pre-trained Model: Ready-to-use with 2000 labeled training samples
- π Web Interface: Beautiful HTML frontend for testing
- π³ Docker Ready: Easy deployment with Docker support
- π Real-time Stats: Performance monitoring and analytics
{
"success": true,
"captcha": "501431",
"solve_time_ms": 95.23,
"model": "2K trained model"
}- Python 3.8 or higher
- pip package manager
- 4GB+ RAM recommended
git clone https://github.com/BijayaKumarTiadi/Captcha-Solver-CNN-Keras-Tensorflow.git
cd Captcha-Solver-CNN-Keras-Tensorflow# Windows
python -m venv venv
venv\Scripts\activate
# Linux/Mac
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtRequired packages:
- tensorflow >= 2.10.0
- keras >= 2.10.0
- fastapi >= 0.104.0
- uvicorn >= 0.24.0
- python-multipart >= 0.0.6
- pillow >= 10.0.0
- numpy >= 1.23.0
- opencv-python >= 4.8.0
python api.pyThe API will be available at: http://localhost:8001
Open your browser and navigate to:
- Swagger UI: http://localhost:8001/docs
- ReDoc: http://localhost:8001/redoc
# Using curl
curl -X POST "http://localhost:8001/solve" -F "file=@images/sample1.png"
# Using Python
python use_2k_model.py images/sample1.pngUpload CAPTCHA image file for solving.
Request:
curl -X POST "http://localhost:8001/solve" \
-F "file=@captcha.png"Response:
{
"success": true,
"captcha": "501431",
"solve_time_ms": 95.23,
"filename": "captcha.png",
"model": "2K trained model"
}Send base64 encoded CAPTCHA image.
Request:
curl -X POST "http://localhost:8001/solve-base64" \
-H "Content-Type: application/json" \
-d '{"image": "base64_string_here"}'Check API health status.
Response:
{
"status": "healthy",
"model_loaded": true,
"model_type": "CNN + BiLSTM with CTC loss",
"training_samples": 2000,
"expected_accuracy": "95%+"
}The model uses a state-of-the-art deep learning architecture combining:
- Convolutional Neural Networks (CNN): Feature extraction
- Bidirectional LSTM: Sequence learning
- CTC Loss: Alignment-free training
Input (182x50x1)
β
Conv2D (32 filters) + ReLU + MaxPool
β
Conv2D (64 filters) + ReLU + MaxPool
β
Reshape + Dense (64)
β
Bidirectional LSTM (128 units)
β
Bidirectional LSTM (64 units)
β
Dense (11 units - 10 digits + blank)
β
CTC Loss
β
Output (6-digit CAPTCHA)
- Parameters: 431,435 (1.65 MB)
- Input Size: 182x50 grayscale
- Output: 6-digit numeric code
- Training Dataset: 2000 labeled images
- Validation Split: 90/10
Organize your CAPTCHA images with filenames as labels:
Captcha_Dataset/solved/
βββ 501431.png
βββ 572143.png
βββ 640741.png
βββ ...
python train_captcha_model.pyEdit train_captcha_model.py to customize:
img_width = 182
img_height = 50
max_length = 6
batch_size = 16
epochs = 100======================================================================
CAPTCHA OCR Model Training
======================================================================
Found 2000 valid CAPTCHA images
Training samples: 1800
Validation samples: 200
Building model...
Total params: 431,435 (1.65 MB)
Starting training...
Epoch 1/100 - loss: 309.04 - val_loss: 244.22
Epoch 2/100 - loss: 253.03 - val_loss: 241.02
...
Epoch 89/100 - loss: 0.75 - val_loss: 0.76
Model saved as 'captcha_model_2k_best.keras'
import requests
# Load and solve CAPTCHA
with open('captcha.png', 'rb') as f:
response = requests.post(
'http://localhost:8001/solve',
files={'file': f}
)
result = response.json()
print(f"CAPTCHA: {result['captcha']}")
print(f"Time: {result['solve_time_ms']}ms")# Single image
python use_2k_model.py captcha.png
# Output:
# Loading 2K trained model...
# Predicting CAPTCHA for: captcha.png
#
# Prediction: 501431const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch('http://localhost:8001/solve', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
console.log('CAPTCHA:', data.captcha);
console.log('Time:', data.solve_time_ms + 'ms');
});| Metric | Value |
|---|---|
| Training Accuracy | 98.5% |
| Validation Accuracy | 95.2% |
| Test Accuracy | 95%+ |
| Operation | Time |
|---|---|
| Model Loading | ~2-3 seconds |
| Single Prediction | ~100ms |
| Batch (100 images) | ~8 seconds |
| Component | Minimum | Recommended |
|---|---|---|
| CPU | 2 cores | 4+ cores |
| RAM | 4GB | 8GB+ |
| Storage | 500MB | 1GB+ |
| GPU | Not required | Recommended for training |
CaptchaSolverCNN/
βββ README.md # This file
βββ LICENSE # MIT License
βββ requirements.txt # Python dependencies
βββ .gitignore # Git ignore rules
β
βββ api.py # FastAPI server
βββ train_captcha_model.py # Model training script
βββ use_2k_model.py # Single prediction script
β
βββ captcha_model_2k_best.keras # Trained model (best)
βββ captcha_model_2k_final.keras # Trained model (final)
β
βββ images/ # Sample images
β βββ sample1.png
β βββ sample2.png
β βββ sample3.png
β βββ sample4.png
β βββ demo.png
β
βββ Captcha_Dataset/
β βββ solved/ # Training data (2000+ images)
β βββ 501431.png
β βββ 572143.png
β βββ ...
β
βββ docs/
βββ API.md # API documentation
βββ TRAINING.md # Training guide
βββ DEPLOYMENT.md # Deployment guide
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PEP 8 style guide
- Add unit tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
This project is licensed under the MIT License - see the LICENSE file for details.
- TensorFlow team for the amazing deep learning framework
- FastAPI for the high-performance API framework
- Keras team for the OCR tutorial inspiration
- Open source community for various tools and libraries
- Support for alphanumeric CAPTCHAs
- Multi-language CAPTCHA recognition
- Real-time video CAPTCHA solving
- Mobile app integration
- Distributed training support
- Model quantization for edge devices
See Issues page for current known issues and feature requests.
If you have any questions or need help:
- π§ Email: bktiadi1@gmail.com
- π¬ Open an Issue
- π Check the Documentation
Made with β€οΈ by Bijaya Kumar Tiadi
β Star this repo if you find it useful! | π Watch for updates | π΄ Fork to contribute
Β© 2025 Bijaya Kumar Tiadi. Licensed under MIT.


