A powerful and efficient CAPTCHA recognition system built with TensorFlow that can recognize text-based CAPTCHAs without requiring image segmentation. This project provides a complete pipeline from CAPTCHA generation to neural network training and recognition.
- No Image Segmentation Required: Direct end-to-end recognition using deep learning
- High Accuracy: Achieves excellent recognition rates with proper training data
- Multi-GPU Support: Train on multiple GPUs for faster training
- Flexible Input: Supports both JPG and PNG image formats
- Easy Training: Simple pipeline from data preparation to model deployment
- Production Ready: Includes evaluation and recognition scripts for real-world use
- OS: Ubuntu 18.04+ (tested on Ubuntu 18.04)
- Python: 3.10+
- Memory: Minimum 8GB RAM (16GB+ recommended for large datasets)
- Python 3.10
- TensorFlow 2.10.0
- NumPy 1.23.4
- captcha package
pip install -r requirements.txt# Install TensorFlow
pip install tensorflow==2.10.0
# Install NumPy
pip install numpy==1.23.4
# Install captcha package
pip install captcha==0.1.1captcha-recognizer/
βββ data/
β βββ train_data/ # Training images
β βββ valid_data/ # Validation images
β βββ test_data/ # Test images
β βββ train.tfrecord # Training dataset (generated)
β βββ valid.tfrecord # Validation dataset (generated)
βββ captcha_gen_default.py # CAPTCHA generation
βββ captcha_records.py # Dataset conversion
βββ captcha_train.py # Single GPU training
βββ captcha_multi_gpu_train.py # Multi-GPU training
βββ captcha_eval.py # Model evaluation
βββ captcha_recognize.py # CAPTCHA recognition
βββ model.py # Neural network architecture
βββ trainer.py # Training logic
βββ predictor.py # Prediction interface
βββ requirements.txt # Python dependencies
Place your CAPTCHA images in the appropriate directories:
- Training:
data/train_data/- for model training - Validation:
data/valid_data/- for model evaluation - Testing:
data/test_data/- for recognition testing
Image Requirements:
- Format: JPG or PNG
- Naming:
label_*.jpgorlabel_*.png(e.g.,ABC123_label_001.jpg) - Size: Recommended 128x48 pixels
- Content: Text-based CAPTCHAs
Or use the built-in generator:
python captcha_gen_default.pyConvert your images to TensorFlow's efficient TFRecord format:
python captcha_records.pyThis creates:
data/train.tfrecord- Training datasetdata/valid.tfrecord- Validation dataset
Single GPU Training:
python captcha_train.pyMulti-GPU Training (faster):
python captcha_multi_gpu_train.pyTraining Tips:
- Accuracy improves with larger training datasets
- More training steps generally yield better results
- Monitor validation accuracy to prevent overfitting
Test your model's accuracy on the validation set:
python captcha_eval.pyUse your trained model to recognize new CAPTCHAs:
python captcha_recognize.pyExample Output:
image WFPMX_num552.png recognize ----> 'WFPMX'
image QUDKM_num468.png recognize ----> 'QUDKM'
The neural network architecture and training parameters can be customized in config.py:
- Input dimensions: Image width and height
- Character set: Supported characters for recognition
- Network architecture: Layer sizes and activation functions
- Training parameters: Learning rate, batch size, epochs
Adjust training parameters in the training scripts:
- Batch size: Adjust based on available GPU memory
- Learning rate: Start with default and tune as needed
- Epochs: More epochs for better accuracy (with proper validation)
- Training Data Size: Larger datasets improve accuracy
- Data Quality: Clean, diverse CAPTCHAs work better
- Training Steps: More iterations generally help
- Model Architecture: Optimized for CAPTCHA recognition
- Use data augmentation for better generalization
- Implement early stopping to prevent overfitting
- Experiment with different learning rates
- Consider ensemble methods for production use
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone the repository
git clone https://github.com/yourusername/captcha-recognizer.git
cd captcha-recognizer
# Install development dependencies
pip install -r requirements.txt
# Run tests
python test_basic.pyThis project is licensed under the MIT License - see the LICENSE file for details.
- CAPTCHA Generator: Gregwar/CaptchaBundle for sample CAPTCHA generation
- TensorFlow: For the deep learning framework
- Community: All contributors and users of this project
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Wiki: Project Wiki
Made with β€οΈ for the open-source community
If you find this project useful, please consider giving it a β star!