Skip to content

About

πŸ”“ Advanced CAPTCHA Solver using Deep Learning (CNN + BiLSTM) - 95%+ accuracy, trained on 2K images

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

16 Commits

Folders and files

Repository files navigation

πŸ”“ CAPTCHA Solver - High Accuracy AI Model

Python TensorFlow FastAPI License Accuracy GitHub Stars

πŸš€ Advanced Deep Learning CAPTCHA Recognition System

Trained on 2000+ labeled images for superior accuracy


πŸ“Ί Live Demo

CAPTCHA Solver Demo


πŸ“‹ Table of Contents


✨ Features

  • 🎯 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

🎬 Demo

Demo GIF

🎯 Sample CAPTCHAs & Results

Input CAPTCHA Prediction Confidence
Sample 1 501431 99.2%
Sample 2 572143 98.7%
Sample 3 788806 97.5%
Sample 4 640741 99.8%

API Response Time

{
  "success": true,
  "captcha": "501431",
  "solve_time_ms": 95.23,
  "model": "2K trained model"
}

πŸ“¦ Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager
  • 4GB+ RAM recommended

Clone the Repository

git clone https://github.com/BijayaKumarTiadi/Captcha-Solver-CNN-Keras-Tensorflow.git
cd Captcha-Solver-CNN-Keras-Tensorflow

Create Virtual Environment

# Windows
python -m venv venv
venv\Scripts\activate

# Linux/Mac
python3 -m venv venv
source venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Required 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

πŸš€ Quick Start

1. Start the API Server

python api.py

The API will be available at: http://localhost:8001

2. Access Swagger UI

Open your browser and navigate to:

3. Test with Sample Image

# Using curl
curl -X POST "http://localhost:8001/solve" -F "file=@images/sample1.png"

# Using Python
python use_2k_model.py images/sample1.png

πŸ“š API Documentation

Endpoints

POST /solve

Upload 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"
}

POST /solve-base64

Send base64 encoded CAPTCHA image.

Request:

curl -X POST "http://localhost:8001/solve-base64" \
     -H "Content-Type: application/json" \
     -d '{"image": "base64_string_here"}'

GET /health

Check API health status.

Response:

{
  "status": "healthy",
  "model_loaded": true,
  "model_type": "CNN + BiLSTM with CTC loss",
  "training_samples": 2000,
  "expected_accuracy": "95%+"
}

🧠 Model Architecture

Overview

The model uses a state-of-the-art deep learning architecture combining:

  1. Convolutional Neural Networks (CNN): Feature extraction
  2. Bidirectional LSTM: Sequence learning
  3. CTC Loss: Alignment-free training

Architecture Details

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)

Model Specifications

  • Parameters: 431,435 (1.65 MB)
  • Input Size: 182x50 grayscale
  • Output: 6-digit numeric code
  • Training Dataset: 2000 labeled images
  • Validation Split: 90/10

πŸŽ“ Training

Prepare Training Data

Organize your CAPTCHA images with filenames as labels:

Captcha_Dataset/solved/
β”œβ”€β”€ 501431.png
β”œβ”€β”€ 572143.png
β”œβ”€β”€ 640741.png
└── ...

Start Training

python train_captcha_model.py

Training Configuration

Edit train_captcha_model.py to customize:

img_width = 182
img_height = 50
max_length = 6
batch_size = 16
epochs = 100

Training Output

======================================================================
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'

πŸ’‘ Usage Examples

Python Script

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")

Command Line

# Single image
python use_2k_model.py captcha.png

# Output:
# Loading 2K trained model...
# Predicting CAPTCHA for: captcha.png
# 
# Prediction: 501431

JavaScript (Web)

const 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');
});

πŸ“Š Performance

Accuracy Metrics

Metric Value
Training Accuracy 98.5%
Validation Accuracy 95.2%
Test Accuracy 95%+

Speed Benchmarks

Operation Time
Model Loading ~2-3 seconds
Single Prediction ~100ms
Batch (100 images) ~8 seconds

System Requirements

Component Minimum Recommended
CPU 2 cores 4+ cores
RAM 4GB 8GB+
Storage 500MB 1GB+
GPU Not required Recommended for training

πŸ“ Project Structure

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

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guide
  • Add unit tests for new features
  • Update documentation as needed
  • Ensure all tests pass before submitting PR

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘€ Author

πŸ‘¨β€πŸ’» Developed by Bijaya Kumar Tiadi

Email LinkedIn Upwork GitHub


πŸ™ Acknowledgments

  • 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

πŸ“ˆ Roadmap

  • Support for alphanumeric CAPTCHAs
  • Multi-language CAPTCHA recognition
  • Real-time video CAPTCHA solving
  • Mobile app integration
  • Distributed training support
  • Model quantization for edge devices

πŸ› Known Issues

See Issues page for current known issues and feature requests.


πŸ“ž Support

If you have any questions or need help:



🌟 Star History

Star History Chart


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.

About

πŸ”“ Advanced CAPTCHA Solver using Deep Learning (CNN + BiLSTM) - 95%+ accuracy, trained on 2K images

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages