Instructions to use gagan3012/TrOCR-Ar-Small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gagan3012/TrOCR-Ar-Small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="gagan3012/TrOCR-Ar-Small")# Load model directly from transformers import AutoTokenizer, AutoModelForImageTextToText tokenizer = AutoTokenizer.from_pretrained("gagan3012/TrOCR-Ar-Small") model = AutoModelForImageTextToText.from_pretrained("gagan3012/TrOCR-Ar-Small") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use gagan3012/TrOCR-Ar-Small with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gagan3012/TrOCR-Ar-Small" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gagan3012/TrOCR-Ar-Small", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/gagan3012/TrOCR-Ar-Small
- SGLang
How to use gagan3012/TrOCR-Ar-Small with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "gagan3012/TrOCR-Ar-Small" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gagan3012/TrOCR-Ar-Small", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "gagan3012/TrOCR-Ar-Small" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gagan3012/TrOCR-Ar-Small", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use gagan3012/TrOCR-Ar-Small with Docker Model Runner:
docker model run hf.co/gagan3012/TrOCR-Ar-Small
what preprocessor should I use to train the handwritten arabic ocr on this base of ArOCR model? #1
Hey, I'm trying to train a handwritten arabic OCR using ArOCR and trOCR-Ar-small, but the preprocessor doesn't load so I used "giganticode/roberta-base-ar_miner" as the tokenizer.
When I check the validation set predictions it's all like a repeated garbage as shown.
here's my loadings:
def load_model(from_disk: bool) -> VisionEncoderDecoderModel:
model: VisionEncoderDecoderModel = VisionEncoderDecoderModel.from_pretrained('gagan3012/TrOCR-Ar-Small')#.from_encoder_decoder_pretrained("google/vit-base-patch16-224-in21k", "giganticode/roberta-base-ar_miner")#
print(f"Using device {device}.")
model.to(device)
return model
def init_model_for_training(model: VisionEncoderDecoderModel, processor: TrOCRProcessor):
model.config.decoder_start_token_id = processor.tokenizer.cls_token_id
model.config.pad_token_id = processor.tokenizer.pad_token_id
model.config.vocab_size = model.config.decoder.vocab_size
model.config.bos_token_id = processor.tokenizer.bos_token_id
model.config.decoder_start_token_id = 0
model.config.decoder.is_decoder = True
model.config.decoder.add_cross_attention = True
def load_processor() -> TrOCRProcessor:
feature_extractor=ViTFeatureExtractor.from_pretrained("google/vit-base-patch16-384")
model_path = "giganticode/roberta-base-ar_miner"
tokenizer = AutoTokenizer.from_pretrained(model_path)
return TrOCRProcessor(feature_extractor=feature_extractor, tokenizer=tokenizer)
Try:
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
