deepseek_ocr_coc

DeepSeek-OCR

DeepSeek-OCR reimagines optical character recognition as a context compression problem — treating visual documents not as images to scan, but as information to compress and decode through an LLM-centric vision encoder. It converts documents, PDFs, and images to clean markdown, extracts text with layout awareness, parses figures, and localizes specific elements by reference — all at ~2500 tokens per second on a single A100 with vLLM. Multiple resolution modes from 64 to 400+ vision tokens let you tune the quality-speed tradeoff for your use case.

MIT
Image-Text-to-Text
PyTorch
Transformers
Safetensors
by @AIOZAI
60
0

Last updated: 3 months ago


Generic badge Generic badge

DeepSeek-OCR: Contexts Optical Compression

Summary

Introduction

DeepSeek-OCR is an initial study on the feasibility of compressing long contexts through 2D optical mapping. DeepSeek-OCR consists of two components: DeepEncoder and DeepSeek3B-MoE-A570M, which acts as the decoder. Specifically, DeepEncoder acts as the core engine, designed to maintain low activation levels under high-resolution input while achieving high compression ratios to ensure an optimal and manageable number of image tokens. Experiments show that when the number of text tokens is within 10 times the number of image tokens (i.e., compression ratio < 10x), the model can achieve decoding accuracy (OCR) of 97%. Even at a compression ratio of 20x, OCR accuracy remains at approximately 60%. This demonstrates significant potential for research areas such as long-term historical context compression and memory forgetting mechanisms in LLMs. Furthermore, DeepSeek-OCR also shows high practical value. On OmniDocBench, it outperforms GOT-OCR2.0 (256 tokens/page) with only 100 image tokens, and far surpasses MinerU2.0 (averaging over 6000 tokens per page) while using fewer than 800 image tokens. In a production environment, DeepSeek-OCR can generate training data for LLM/VLMs on a scale of over 200,000 pages per day (on a single A100-40G machine). The source code and model weights are publicly available at https://github.com/deepseek-ai/DeepSeek-OCR.

Parameters

Inputs

  • input_image - (image -.png|.jpg|.jpeg): A document page, PDF screenshot, or image containing text, figures, or structured content to be processed.
  • model_size - (text): Specifies the model variant to use. Available options:"Tiny", "Small", "Base", "Large", "Gundam (Recommended)"
  • task_type - (text): Defines the type of task to perform. Supported options: "📝 Free OCR", "📄 Convert to Markdown", "📈 Parse Figure", "🔍 Locate Object by Reference"
  • ref_text - (text): A reference description of the object to locate. Required only when task_type = "🔍 Locate Object by Reference". Ignored for all other task types.

Output

  • text_result - (text): The textual result generated by the model, depending on the selected task.
  • output_image - (image -.png): The resulting image after processing. This may include visual annotations such as bounding boxes, highlighted objects, or other overlays depending on the task.

Usage for developers

Please find below the details to track the information and access the code for processing the model on our platform.

Requirements

pip install -r requirements.txt

Code based on AIOZ structure

from transformers import AutoModel, AutoTokenizer
import torch
import os
import tempfile
from PIL import Image, ImageDraw
import re

def load_model():
  ...

def do_ai_task(
        input_image: Union[str, Path],
        task_type: Union[str, str],
        ref_text: Union[str, str],
        model_size: Union[str, str],
        model_storage_directory: Union[str, Path],
        device: Literal["cpu", "cuda", "gpu"] = "cpu",
        *args, **kwargs) -> Any:
    """Define AI task: load model, pre-process, post-process, etc ..."""
    # Define AI task workflow. Below is an example
    
    model, tokenizer = load_model(model_storage_directory)
    model_gpu = model.cuda().to(torch.bfloat16)
    ...
    
    result_image_pil.save("output.png")
    output_image = open("output.png", "rb")  # io.BufferedReader
    return text_result, output_image

Visualizations

Reference

This repository is based on and inspired by deepseek-ai's work. We sincerely appreciate their generosity in sharing the code.

License

We respect and comply with the terms of the author's license cited in the Reference section.

Citation

@article{wei2025deepseek,
  title={DeepSeek-OCR: Contexts Optical Compression},
  author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
  journal={arXiv preprint arXiv:2510.18234},
  year={2025}
}