查看 Markdown

DeepSeek-OCR

DeepSeek-OCR 是 DeepSeek 面向文档的 3B 混合专家模型。LibreYOLO 通过内置的 PyTorch 移植版在 ocr 任务上运行 DeepSeek-OCR 和 DeepSeek-OCR-2:输出带检测框的文本行、版面块,或把整页转成 markdown。

任务
ocr
尺寸
1, 2 at 1024 px
安装
pip install "libreyolo[vlm]"
支持层级
兄弟层级,自 v1.8.0 起。一个独立的产品面,有自己的工厂和契约。
上游
DeepSeek-OCR,由 DeepSeek 发布,采用 MIT (size 1); Apache-2.0 (size 2) 许可。论文、源码
许可
代码采用 MIT (DeepSeek-OCR); Apache-2.0 (DeepSeek-OCR 2),权重采用 MIT (DeepSeek-OCR); Apache-2.0 (DeepSeek-OCR 2)。商用

安装

DeepSeek-OCR 属于 LibreYOLO 的 VLM 层级,需要 vlm extra。

bash
pip install "libreyolo[vlm]"

预测

权重在首次使用时从逐字节一致的 LibreYOLO 镜像下载,即 LibreYOLO/LibreDeepSeekOCR1 和 LibreYOLO/LibreDeepSeekOCR2,固定到某个 revision。架构是发布版推理路径的 PyTorch 移植;不运行任何远程代码。

Python
from libreyolo import LibreVLM model = LibreVLM("deepseek-ocr")      # 权重在首次使用时下载result = model.predict("page.png")     # 一张扫描或渲染出来的页面 for text, quad in zip(result.ocr.texts, result.ocr.polygons):    print(text, quad.tolist())         # 每个文本行一个区域
Markdown
from libreyolo import LibreVLM model = LibreVLM("deepseek-ocr", prompt="markdown")result = model.predict("page.png") print(result.ocr.markdown)             # 整页的 markdownprint(result.ocr.labels)               # 每个块的版面类别
DeepSeek-OCR-2
from libreyolo import LibreVLM model = LibreVLM("deepseek-ocr-2")     # 分辨率为 "gundam" 或 "base"result = model.predict("page.png")print(result.ocr.texts)

这个家族通过 LibreVLM() 或 LibreDeepSeekOCR 类加载。prompt 设置(在构造时 或通过 set_prompt())决定 Results.ocr 里放什么:

promptResults.ocr
"ocr"(默认)每个文本行一个区域,labels 全为 text,markdown 为空
"markdown"每个版面块一个区域,版面类别在 labels 里,整页在 markdown 里
"free"没有区域,页面文本在 markdown 里
其他任意字符串模型输出的任何定位(grounding)结果,外加 markdown

检测框以模型的 0 到 999 网格给出,再缩放回原图,成为轴对齐的 4 点四边形,按从上 到下、再从左到右排序。生成式模型不输出分数,所以 conf 和 det_conf 恒为 1.0。 model.chat("page.png", "Parse the figure.") 对任意提示词返回原始生成文本。解码 采用贪心解码,最多生成 8192 个新 token,并像发布版一样使用 no_repeat_ngram_size=20。

变体

名称模型分辨率许可证
deepseek-ocrDeepSeek-OCR(尺寸 1)tiny(512)、small(640)、base(1024)、large(1280)、gundam(默认)MIT
deepseek-ocr-2DeepSeek-OCR-2(尺寸 2)base(1024)、gundam(默认)Apache-2.0

gundam 把一个 1024 px 的全局视图和局部裁剪结合起来:DeepSeek-OCR 上是 2 到 9 个 640 px 的裁剪,DeepSeek-OCR-2 上最多 6 个 768 px 的裁剪。DeepSeek-OCR-2 保留了 解码器和 SAM 阶段,把 CLIP 换成了 Qwen2 编码器;提示词和输出相同。

CUDA 上像发布版一样在 torch.autocast 下运行 bf16 权重(不支持 bf16 的 GPU 上用 fp16)。CPU 和 MPS 以 float32 和 eager 注意力运行,约占 13 GB 内存;MPS 尚未在 硬件上运行过。不应用 EXIF 方向信息。在 RTX 3090 上,移植版在 DeepSeek-OCR 的 17 个 用例和 DeepSeek-OCR-2 的 14 个用例上与发布版逐 token 一致。基准测试数字见发布版 论文,LibreYOLO 没有复现。

验证

val() 运行共用的 OCR 验证器,报告检测 hmean、端到端 F1 和 1-NED。

Python
from libreyolo import LibreVLM model = LibreVLM("deepseek-ocr")metrics = model.val(data="ocr_dataset/")   # 检测 hmean、端到端 F1、1-NED

导出

仅支持推理:train() 和 export() 会抛出异常。

许可证

请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。

这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。

原始工作
DeepSeek-OCR, DeepSeek
上游许可
MIT (size 1); Apache-2.0 (size 2)
LibreYOLO 代码
MIT
权重
采用 MIT (DeepSeek-OCR); Apache-2.0 (DeepSeek-OCR 2) 许可,重新发布在 huggingface.co/LibreYOLO
解读
This family covers two releases with different permissive licences. Size "1" is DeepSeek-OCR (paper arXiv:2510.18234), released under MIT: commercial and closed-source use is allowed if you keep the copyright and license notice. Size "2" is DeepSeek-OCR 2 (paper arXiv:2601.20552, 'Visual Causal Flow'), released under Apache-2.0: commercial use is allowed if you keep the license text and notices, and it grants a patent license. LibreYOLO ports the inference path of the Hugging Face releases (deepseek-ai/DeepSeek-OCR at 9f30c71f441d010e5429c532364a86705536c53a and deepseek-ai/DeepSeek-OCR-2 at aaa02f3811945a91062062994c5c4a3f4c0af2b0) and runs none of their remote code; ported parts keep their lineage, Apache-2.0 for the DeepSeek-V2 decoder, the Transformers Llama and Qwen2 attention, the detectron2-derived SAM encoder and the FastChat template, MIT for the ConvNeXt LayerNorm (libreyolo/models/deepseekocr/NOTICE), while the adapter is MIT. Weights are byte-identical, ungated mirrors at LibreYOLO/LibreDeepSeekOCR1 and LibreYOLO/LibreDeepSeekOCR2 with no learned parameter changed.

DeepSeek-OCR 采用 MIT 许可,DeepSeek-OCR-2 采用 Apache-2.0 许可,代码和权重都是如此, 均出自 DeepSeek。两者都允许商用。 权重是逐字节一致、不需要申请访问的镜像。

引用

@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}
}

复制自作者在 huggingface.co/deepseek-ai/DeepSeek-OCR#citation 上提供的引用块。

已针对 LibreYOLO v1.8.0 验证。本页的支持表、检查点和基准测试数据由已发布的库和权重生成,并非手工编写。