Views
No views yet
[!WARNING] THIS IS A PRELIMINARY BASELINE MODEL AND IS NOT RECOMMENDED FOR PRODUCTION USE.
- Performance: This model (Version 3) has a high Character Error Rate (CER) of ~79%. It struggles with sentence context, frequently omits characters, and fails on complex cursive ligatures.
- Next Version Coming Soon: Koshur OCR v4 is actively training and will offer a massive drop in CER, vastly superior accuracy, and full Nastaliq/Naskh support. Please wait for the v4 release!
ۆ, ۄ, and ؠ). Version 3 serves as the initial pilot implementation extending TrOCR to handle these character mappings.RayR1/trocr-base-arabic-handwritten to leverage its strong baseline understanding of cursive Perso-Arabic script lines and characters.ks) written in the modified Perso-Arabic script.Omarrran/600k_KS_OCR_Word_Segmented_Dataset): A collection of synthetic, single-word cropped images in diverse fonts (Naskh, Nastaliq, Nakash) and background textures.Omarrran/Koshur_Pixel): Sentence-line and mixed paragraph text lines to teach the decoder spelling, grammar, and RTL reading order.num_beams=1), it makes spelling mistakes.transformers library:1import torch
2from PIL import Image
3from transformers import VisionEncoderDecoderModel, TrOCRProcessor
4
5# 1. Load the model and processor
6device = "cuda" if torch.cuda.is_available() else "cpu"
7model_name = "Faizaniqbal/Koshur-OCR-v3-checkpoints"
8
9processor = TrOCRProcessor.from_pretrained(model_name)
10model = VisionEncoderDecoderModel.from_pretrained(model_name).to(device)
11
12# 2. Prepare an image
13# Make sure your image is cropped to a line of Kashmiri text
14image_path = "path/to/your/kashmiri_text_line.png"
15image = Image.open(image_path).convert("RGB")
16
17# 3. Preprocess and generate text
18pixel_values = processor(image, return_tensors="pt").pixel_values.to(device)
19
20# We recommend using Beam Search (num_beams=4) for better results in V3
21generated_ids = model.generate(
22 pixel_values,
23 max_length=128,
24 num_beams=4,
25 early_stopping=True
26)
27
28predicted_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
29print("Predicted Kashmiri Text:", predicted_text.strip())