English | 中文
General Chinese–English Bilingual OCR.
YesOCR-0.8B turns text in Chinese, English, and mixed-language images into editable plain text. Use it to transcribe document pages, screenshots, receipts, signs, and other everyday images. It aims to follow reading order and preserve the original text and line breaks.
The model is fine-tuned from Qwen3.5-0.8B, primarily using the OCR-Data dataset.
Use Python 3.10 or newer. A GPU is recommended for faster recognition; CPU inference is also supported.
Download the model, install its dependencies, and recognize the included example image:
python -m pip install huggingface_hub
hf download Yesianrohn/YesOCR-0.8B --local-dir ./YesOCR-0.8B
cd YesOCR-0.8B
python -m pip install -r requirements.txt
python inference.py --model . --image example.png --output result.txt
The recognized text is printed in the terminal and saved to result.txt:
YesOCR demo
Order: A1024
Total: 128.50
Replace your-image.png with the path to your image:
python inference.py --model . --image your-image.png --output result.txt
The same command works for Chinese, English, and mixed-language images. There is no need to select a language. The result is a transcription of the original text.
The script automatically uses a GPU when one is available. Add --device cpu to run on CPU.
Once the model and dependencies are downloaded, --model . lets you use the local files offline.
You can also load Yesianrohn/YesOCR-0.8B directly in Python.
The example below uses a CUDA GPU with BF16 support. Replace example.png with your image path;
keep the provided OCR prompt for both Chinese and English images.
import torch
from PIL import Image, ImageOps, PngImagePlugin
from transformers import AutoModelForImageTextToText, AutoProcessor
MODEL_ID = "Yesianrohn/YesOCR-0.8B"
# Allow PNGs with large compressed color profiles.
PngImagePlugin.MAX_TEXT_CHUNK = 64 * 1024 * 1024
PngImagePlugin.MAX_TEXT_MEMORY = 256 * 1024 * 1024
processor = AutoProcessor.from_pretrained(MODEL_ID)
model = AutoModelForImageTextToText.from_pretrained(
MODEL_ID,
dtype=torch.bfloat16,
attn_implementation="sdpa",
).to("cuda").eval()
with Image.open("example.png") as source:
image = ImageOps.exif_transpose(source).convert("RGB")
prompt = (
"请按阅读顺序转录图片中的全部可辨认文字,保留原文和换行,文本块之间空一行。"
"仅输出转录结果。"
)
messages = [{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": "\n" + prompt},
],
}]
text = processor.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=False,
)
inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
with torch.inference_mode():
output_ids = model.generate(
**inputs,
max_new_tokens=4096,
do_sample=False,
num_beams=1,
use_cache=True,
)
# Decode only the newly generated tokens.
new_tokens = output_ids[:, inputs["input_ids"].shape[1]:]
result = processor.batch_decode(new_tokens, skip_special_tokens=True)[0].strip()
image.close()
print(result)
For CPU inference, replace dtype=torch.bfloat16 with dtype=torch.float32
and .to("cuda") with .to("cpu").
--max-new-tokens 8192.--max-pixels 1000000.Published by Yesianrohn under the Apache License 2.0. Thanks to the Qwen team for the base model. See NOTICE for attribution.
Qwen/Qwen3.5-0.8B