Image-Text-to-Text
PaddleOCR
Safetensors
English
Chinese
multilingual
paddleocr_vl
ERNIE4.5
PaddlePaddle
image-to-text
ocr
document-parse
layout
table
formula
chart
conversational
custom_code
Eval Results
Run this model with HF Jobs
Run PaddlePaddle/PaddleOCR-VL on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/PaddlePaddle/PaddleOCR-VL. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/PaddlePaddle/PaddleOCR-VL on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/PaddlePaddle/PaddleOCR-VL. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/PaddlePaddle/PaddleOCR-VL. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use PaddlePaddle/PaddleOCR-VL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PaddleOCR
How to use PaddlePaddle/PaddleOCR-VL with PaddleOCR:
# See https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html to installation from paddleocr import PaddleOCRVL pipeline = PaddleOCRVL(pipeline_version="v1") output = pipeline.predict("path/to/document_image.png") for res in output: res.print() res.save_to_json(save_path="output") res.save_to_markdown(save_path="output") - Notebooks
- Google Colab
- Kaggle
zhangyue66 commited on
Commit ·
4fe79f6
1
Parent(s): 1787ca5
update
Browse files148 unmodified lines1491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122133 unmodified lines2172182192202212222232242252262 unmodified lines229230231232233234235236237238239148 unmodified lines> [!NOTE]> Note: We currently recommend using the official method for inference, as it is faster and supports page-level document parsing. The example code below only supports element-level recognition.```bash# 1- ensure the flash-attn2 is installed!uv pip install -q "transformers>=4.55" bitsandbytes accelerate!uv pip install flash-attn --no-build-isolation``````python# 1.2 import the necessary librariesimport torchfrom transformers import AutoModelForCausalLM, AutoProcessorfrom PIL import Imagefrom google.colab import files# 2- Upload image (drag & drop any PNG/JPG)uploaded = files.upload()image_path = list(uploaded.keys())[-1]print(f"Using: {image_path}")# 3. Resize max-2048 preserving aspect ratioimg = Image.open(image_path).convert("RGB")max_size = 2048w, h = img.sizeif max(w, h) > max_size:scale = max_size / max(w, h)new_w, new_h = int(w * scale), int(h * scale)img = img.resize((new_w, new_h), Image.LANCZOS)print(f"Resized → {img.size[0]}×{img.size[1]}")print(f"current dim → {img.size[0]}×{img.size[1]}")#4. Load modelDEVICE = "cuda" if torch.cuda.is_available() else "cpu"model = AutoModelForCausalLM.from_pretrained("PaddlePaddle/PaddleOCR-VL",trust_remote_code=True,torch_dtype=torch.bfloat16,attn_implementation="flash_attention_2",).to(dtype=torch.bfloat16, device=DEVICE).eval()processor = AutoProcessor.from_pretrained("PaddlePaddle/PaddleOCR-VL", trust_remote_code=True)# 5. Choose taskTASK = "ocr" # ← change to "table" | "chart" | "formula"PROMPTS = {"ocr": "OCR:","table": "Table Recognition:","chart": "Chart Recognition:","formula": "Formula Recognition:",}# 6. Run inferencemessages = [{"role": "user", "content": [{"type": "image", "image": img},{"type": "text", "text": PROMPTS[TASK]}]}]inputs = processor.apply_chat_template(messages,3 unmodified linesreturn_tensors="pt").to(DEVICE)# 7. Run inferencewith torch.inference_mode():out = model.generate(**inputs,2 unmodified linesuse_cache=True)# 8. Decode the outputresult = processor.batch_decode(out, skip_special_tokens=True)[0]print("\n" + "="*60 + "\nRESULT:\n" + "="*60)print(result)```## Performance148 unmodified lines1491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452463 unmodified lines2502512522532542552 unmodified lines258259260261262263264265266267268148 unmodified lines> [!NOTE]> Note: We currently recommend using the official method for inference, as it is faster and supports page-level document parsing. The example code below only supports element-level recognition.```pythonfrom PIL import Imageimport torchfrom transformers import AutoModelForCausalLM, AutoProcessor# ---- Settings ----model_path = "PaddlePaddle/PaddleOCR-VL"image_path = "test.png"task = "ocr" # Options: 'ocr' | 'table' | 'chart' | 'formula'# ------------------DEVICE = "cuda" if torch.cuda.is_available() else "cpu"PROMPTS = {"ocr": "OCR:","table": "Table Recognition:","formula": "Formula Recognition:","chart": "Chart Recognition:",}image = Image.open(image_path).convert("RGB")model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, torch_dtype=torch.bfloat16).to(DEVICE).eval()processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)messages = [{"role": "user","content": [{"type": "image", "image": image},{"type": "text", "text": PROMPTS[task]},]}]inputs = processor.apply_chat_template(messages,tokenize=True,add_generation_prompt=True,return_dict=True,return_tensors="pt").to(DEVICE)outputs = model.generate(**inputs, max_new_tokens=1024)outputs = processor.batch_decode(outputs, skip_special_tokens=True)[0]print(outputs)```<details><summary>👉 Click to expand: Use flash-attn to boost performance and reduce memory usage</summary><pre><code># ensure the flash-attn2 is installedpip install flash-attn --no-build-isolation</code></pre><pre><code>import torchfrom transformers import AutoModelForCausalLM, AutoProcessorfrom PIL import Image# ---- Settings ----model_path = "PaddlePaddle/PaddleOCR-VL"image_path = "test.png"task = "ocr" # ← change to "table" | "chart" | "formula"# ------------------DEVICE = "cuda" if torch.cuda.is_available() else "cpu"model = AutoModelForCausalLM.from_pretrained(model_path,trust_remote_code=True,torch_dtype=torch.bfloat16,attn_implementation="flash_attention_2",).to(dtype=torch.bfloat16, device=DEVICE).eval()processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)PROMPTS = {"ocr": "OCR:","table": "Table Recognition:","chart": "Chart Recognition:","formula": "Formula Recognition:",}messages = [{"role": "user","content": [{"type": "image", "image": Image.open(image_path).convert("RGB")},{"type": "text", "text": PROMPTS[task]}]}]inputs = processor.apply_chat_template(messages,3 unmodified linesreturn_tensors="pt").to(DEVICE)with torch.inference_mode():out = model.generate(**inputs,2 unmodified linesuse_cache=True)outputs = processor.batch_decode(out, skip_special_tokens=True)[0]print(outputs)</code></pre></details>## Performance
README.md+74-45