Image-to-Text
Transformers
Safetensors
vision-encoder-decoder
image-text-to-text
trocr
ocr
captcha
digits-captcha
synthetic-data
Instructions to use arkhabbazan/ocr-digits-captcha with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use arkhabbazan/ocr-digits-captcha with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("image-to-text", model="arkhabbazan/ocr-digits-captcha")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("arkhabbazan/ocr-digits-captcha") model = AutoModelForMultimodalLM.from_pretrained("arkhabbazan/ocr-digits-captcha", device_map="auto") - Notebooks
- Google Colab
- Kaggle
OCR Digits Captcha
A TrOCR model fine-tuned to recognize short numeric captchas of 4 or 5 digits
such as 4829 and 50942.
![]() |
![]() |
![]() |
![]() |
Model details
- Architecture: Vision Encoder-Decoder / TrOCR
- Base model:
microsoft/trocr-base-printed - Task: Image-to-text OCR
- Target geometry: 145x56 and 120x48 RGB images
- Output: Digit strings of 4 or 5 digits
Training configuration
| Parameter | Value |
|---|---|
| Epochs | 6 |
| Learning rate | 2e-5 |
| Batch size | 8 |
| Gradient accumulation | 2 |
| Weight decay | 0.01 |
| Generation beams | 4 |
| Maximum output length | 16 |
Evaluation
The model was trained and evaluated on synthetic captchas generated at the target size and format. Real-world accuracy was not measured on a held-out real set, so the scores below do not prove it.
| Split | Samples | Exact match | Character accuracy |
|---|---|---|---|
| Validation | 1500 | 99.93% | 99.98% |
| Synthetic test | 750 | 100.00% | 100.00% |
Usage
from PIL import Image
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
repo_id = "arkhabbazan/ocr-digits-captcha"
processor = TrOCRProcessor.from_pretrained(repo_id)
model = VisionEncoderDecoderModel.from_pretrained(repo_id).eval()
image = Image.open("captcha.png").convert("RGBA")
white = Image.new("RGBA", image.size, (255, 255, 255, 255))
white.alpha_composite(image)
pixel_values = processor(images=white.convert("RGB"), return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values, num_beams=4, max_length=16)
prediction = processor.batch_decode(
generated_ids, skip_special_tokens=True
)[0]
print(prediction.replace(" ", ""))
Limitations
- Training data is primarily synthetic.
- Unseen fonts and layouts may reduce accuracy.
- The model is intended for short digit strings, not document OCR.
- Usage must be authorized and compliant with applicable policies.
- Downloads last month
- 40
Model tree for arkhabbazan/ocr-digits-captcha
Base model
microsoft/trocr-base-printed


