Instructions to use arcma/decap with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use arcma/decap with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="arcma/decap")# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("arcma/decap") model = AutoModelForMultimodalLM.from_pretrained("arcma/decap") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use arcma/decap with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "arcma/decap" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "arcma/decap", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/arcma/decap
- SGLang
How to use arcma/decap 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 "arcma/decap" \ --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": "arcma/decap", "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 "arcma/decap" \ --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": "arcma/decap", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use arcma/decap with Docker Model Runner:
docker model run hf.co/arcma/decap
ArcMa commited on
Commit ·
5c7d112
1
Parent(s): 223ee14
README.md
CHANGED
|
@@ -1,61 +1 @@
|
|
| 1 |
-
---
|
| 2 |
-
tags:
|
| 3 |
-
- trocr
|
| 4 |
-
- image-to-text
|
| 5 |
-
widget:
|
| 6 |
-
- src: https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X00016469612_1.jpg
|
| 7 |
-
example_title: Printed 1
|
| 8 |
-
- src: https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005255805_7.jpg
|
| 9 |
-
example_title: Printed 2
|
| 10 |
-
- src: https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005745214_6.jpg
|
| 11 |
-
example_title: Printed 3
|
| 12 |
-
---
|
| 13 |
|
| 14 |
-
# TrOCR (small-sized model, fine-tuned on SROIE)
|
| 15 |
-
|
| 16 |
-
TrOCR model fine-tuned on the [SROIE dataset](https://rrc.cvc.uab.es/?ch=13). It was introduced in the paper [TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models](https://arxiv.org/abs/2109.10282) by Li et al. and first released in [this repository](https://github.com/microsoft/unilm/tree/master/trocr).
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
## Model description
|
| 20 |
-
|
| 21 |
-
The TrOCR model is an encoder-decoder model, consisting of an image Transformer as encoder, and a text Transformer as decoder. The image encoder was initialized from the weights of DeiT, while the text decoder was initialized from the weights of UniLM.
|
| 22 |
-
|
| 23 |
-
Images are presented to the model as a sequence of fixed-size patches (resolution 16x16), which are linearly embedded. One also adds absolute position embeddings before feeding the sequence to the layers of the Transformer encoder. Next, the Transformer text decoder autoregressively generates tokens.
|
| 24 |
-
|
| 25 |
-
## Intended uses & limitations
|
| 26 |
-
|
| 27 |
-
You can use the raw model for optical character recognition (OCR) on single text-line images. See the [model hub](https://huggingface.co/models?search=microsoft/trocr) to look for fine-tuned versions on a task that interests you.
|
| 28 |
-
|
| 29 |
-
### How to use
|
| 30 |
-
|
| 31 |
-
Here is how to use this model in PyTorch:
|
| 32 |
-
|
| 33 |
-
```python
|
| 34 |
-
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
| 35 |
-
from PIL import Image
|
| 36 |
-
import requests
|
| 37 |
-
|
| 38 |
-
# load image from the IAM database (actually this model is meant to be used on printed text)
|
| 39 |
-
url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg'
|
| 40 |
-
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
| 41 |
-
|
| 42 |
-
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-small-printed')
|
| 43 |
-
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-small-printed')
|
| 44 |
-
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
| 45 |
-
|
| 46 |
-
generated_ids = model.generate(pixel_values)
|
| 47 |
-
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 48 |
-
```
|
| 49 |
-
|
| 50 |
-
### BibTeX entry and citation info
|
| 51 |
-
|
| 52 |
-
```bibtex
|
| 53 |
-
@misc{li2021trocr,
|
| 54 |
-
title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models},
|
| 55 |
-
author={Minghao Li and Tengchao Lv and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},
|
| 56 |
-
year={2021},
|
| 57 |
-
eprint={2109.10282},
|
| 58 |
-
archivePrefix={arXiv},
|
| 59 |
-
primaryClass={cs.CL}
|
| 60 |
-
}
|
| 61 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|