Bangla OCR 🇧🇩
The Best Bangla/Bengali OCR Package - Recognize Bangla text from images with zero dependency conflicts!
✨ Why Bangla OCR?
- 🔤 Accurate: State-of-the-art Transformer architecture for Bangla text recognition
- 🚀 Zero Conflicts: Works with ANY version of PyTorch, NumPy - no dependency hell!
- ☁️ Cloud Ready: Works instantly on Google Colab, Kaggle, AWS, GCP, Azure
- 💻 Cross-Platform: Windows, Linux, macOS, Apple Silicon (M1/M2/M3/M4)
- 🎯 Smart Fallbacks: Works even without OpenCV (uses PIL as fallback)
- 📥 Multiple Inputs: Accepts file paths, PIL Images, numpy arrays, URLs, and bytes
- ⚡ Fast: GPU acceleration with CUDA and Apple MPS support
📦 Installation
pip install bangla-ocr
That's it! Works everywhere - Colab, Kaggle, local, Docker, cloud!
Optional: With OpenCV (slightly better preprocessing)
pip install bangla-ocr[cv-headless] # Recommended for servers/Colab/Kaggle
pip install bangla-ocr[cv] # For local development with GUI
pip install bangla-ocr[full] # Everything included
🚀 Quick Start
from bangla_ocr import BanglaOCR
# Initialize (automatically downloads model on first run)
ocr = BanglaOCR()
# Recognize text from an image
text = ocr.recognize('bangla_image.jpg')
print(text) # Output: বাংলা টেক্সট
📖 Usage Examples
From File Path
text = ocr.recognize('path/to/image.jpg')
From PIL Image
from PIL import Image
img = Image.open('image.png')
text = ocr.recognize(img)
From NumPy Array
import numpy as np
arr = np.array(Image.open('image.jpg'))
text = ocr.recognize(arr)
From URL
text = ocr.recognize('https://example.com/bangla_image.jpg')
From Bytes
with open('image.jpg', 'rb') as f:
img_bytes = f.read()
text = ocr.recognize(img_bytes)
Batch Prediction
texts = ocr.predict_batch(
['img1.jpg', 'img2.jpg', 'img3.jpg'],
show_progress=True
)
for text in texts:
print(text)
🔧 Advanced Configuration
Check System Status
from bangla_ocr import check_dependencies, print_info
# Print formatted info
print_info()
# Get dependency status
status = check_dependencies()
print(status)
# {'torch': True, 'cuda': True, 'mps': False, 'opencv': True, ...}
Device Selection
# Auto-detect best device (default)
ocr = BanglaOCR()
# Force specific device
ocr = BanglaOCR(device='cpu') # CPU
ocr = BanglaOCR(device='cuda') # NVIDIA GPU
ocr = BanglaOCR(device='mps') # Apple Silicon
Custom Model Parameters
ocr = BanglaOCR(
model_path='custom_model.pth',
tokenizer_path='tokenizer.pk',
d_model=256, # Hidden dimension
nheads=4, # Attention heads
num_decoder_layers=4 # Decoder layers
)
Get Model Info
ocr = BanglaOCR()
print(ocr.info)
# {'version': '1.0.0', 'device': 'cuda', 'd_model': 256, ...}
🏗️ Architecture
Input Image → ResNet-18 (CNN Encoder) → Transformer Decoder → Bangla Text
- Encoder: ResNet-18 backbone for visual feature extraction
- Positional Encoding: Sine encodings for spatial information
- Decoder: Transformer with multi-head attention
- Output: Character-level Bangla vocabulary
📋 Requirements
| Package | Version | Notes |
|---|---|---|
| Python | ≥ 3.8 | 3.9-3.12 recommended |
| PyTorch | ≥ 1.9.0 | Any version works |
| torchvision | ≥ 0.10.0 | Any version works |
| NumPy | ≥ 1.19.0 | Any version works |
| Pillow | ≥ 8.0.0 | Always used |
| OpenCV | Optional | PIL fallback available |
🌍 Platform Compatibility
| Platform | Status | Acceleration |
|---|---|---|
| Google Colab | ✅ Perfect | CUDA |
| Kaggle | ✅ Perfect | CUDA/TPU |
| Windows 10/11 | ✅ Perfect | CUDA |
| Linux (Ubuntu, etc.) | ✅ Perfect | CUDA |
| macOS Intel | ✅ Perfect | CPU |
| macOS Apple Silicon | ✅ Perfect | MPS |
| Docker | ✅ Perfect | CUDA |
| AWS/GCP/Azure | ✅ Perfect | CUDA |
🏋️ Training
Install training dependencies:
pip install bangla-ocr[train]
See the training guide for details.
📚 Citation
@inproceedings{ghosh2023bangla,
title={Towards Full-page Offline Bangla Handwritten Text Recognition},
author={Ghosh, A.},
booktitle={IEEE SILCON},
year={2023}
}
📄 License
MIT License - see LICENSE for details.
🤝 Contributing
Contributions welcome! Please submit a Pull Request.
Metadata
Release files for bangla-ocr 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bangla_ocr-1.0.3.tar.gz | 18.7 kB | Without provenance | Details for bangla_ocr-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bangla_ocr-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for bangla_ocr-1.0.3-py3-none-any.whl |
Total release size: 36.2 kB
Release files / bangla_ocr-1.0.3.tar.gz
| Download URL | bangla_ocr-1.0.3.tar.gz |
|---|---|
| Size | 18.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
935f24eab9bdcbb13bb8009ad646393ad675394ea687e86f453984f14029565c
|
|
BLAKE2b-256 checksum How to use checksums |
e2e051527ac7b7a4367c35dc06ef6e2a4e9897ba5d57b44727633e3f4ef2c7fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / bangla_ocr-1.0.3-py3-none-any.whl
| Download URL | bangla_ocr-1.0.3-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1eb6d213608f162e57db795105f71bb0c9e06f59d9b8ee1bf3bf49b7010940a
|
|
BLAKE2b-256 checksum How to use checksums |
dd97df0d8de4e4966ad607f2f2e646ede41799f709b27720ae2500aeec61b649
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for bangla-ocr 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.