Summary: GLM-OCR is a lightweight OCR model achieving SOTA performance with just 90M parameters. It excels in document parsing, table/formula recognition, and supports multiple languages and deployment options.
点击下方名片关注AIGC Studio公众号!获取最新AI前沿应用/AIGC实践教程!
GLM-OCR 是一款轻量级的专业 OCR 模型,参数量仅为 0.9 字节,却在多项功能上实现了顶尖的性能。它以"体积小、精度高"的特点,为文档解析树立了新的标杆。目前已经冲到了Huggingface热门榜单Top1!
主要特性包括:
性能 SOTA :在 OmniDocBench V1.5 中获得 94.62 分,位居榜首,并在发布时在包括表格和公式在内的多个主流文档理解基准测试中实现了当前最佳性能。 针对实际应用场景优化:在代码文档、复杂表格和印章识别等复杂环境中,提供稳定、领先的识别精度。即使面对复杂的布局、多样化的字体或混合的文本图像内容,也能保持卓越的识别精度。 高效且经济:仅需 0.9 亿个参数,支持 VLLM 和 SGLang 部署,显著降低推理延迟和计算开销。
输入方式:PDF、图像(JPG、PNG) 单张图片≤10MB,PDF文件≤50MB 最大支持页数:100 页
输出方式: 文本/图像链接/MD文档
**支持的语言:**支持中文、英文、法文、西班牙文、俄文、德文、日文、韩文等语言。
效果展示
代码块识别
表格识别
账单识别
手写识别
相关链接
模型:https://huggingface.co/zai-org/GLM-OCR#performance 介绍: https://docs.z.ai/guides/vlm/glm-ocr
性能表现
文档解析与信息提取
真实场景表现
速度测试
为了比较速度,在相同的硬件和测试条件下(单副本、单并发),对不同的OCR方法进行了比较,评估了它们在解析和导出图像及PDF输入文件的Markdown文件方面的性能。结果表明,GLM-OCR对PDF文档的处理速度为1.86页/秒,对图像的处理速度为0.67张/秒,显著优于其他同类模型。
部署教程
VLLM
pip install -U vllm --extra-index-url https://wheels.vllm.ai/nightly
或者使用 Docker:
docker pull vllm/vllm-openai:nightly
运行方式:
pip install git+https://github.com/huggingface/transformers.git
vllm serve zai-org/GLM-OCR --allowed-local-media-path / --port 8080
SGLang
使用 Docker:
docker pull lmsysorg/sglang:dev
或者使用以下命令从源代码构建:
pip install git+https://github.com/sgl-project/sglang.git#subdirectory=python
运行方式:
pip install git+https://github.com/huggingface/transformers.git
python -m sglang.launch_server --model zai-org/GLM-OCR --port 8080
Ollama
运行方式:
ollama run glm-ocr
当图片被拖入终端时,Ollama 会自动使用图片文件路径:
ollama run glm-ocr Text Recognition: ./image.png
Transformer
pip install git+https://github.com/huggingface/transformers.git
from transformers import AutoProcessor, AutoModelForImageTextToText
import torch
MODEL_PATH = "zai-org/GLM-OCR"
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"url": "test_image.png"
},
{
"type": "text",
"text": "Text Recognition:"
}
],
}
]
processor = AutoProcessor.from_pretrained(MODEL_PATH)
model = AutoModelForImageTextToText.from_pretrained(
pretrained_model_name_or_path=MODEL_PATH,
torch_dtype="auto",
device_map="auto",
)
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt"
).to(model.device)
inputs.pop("token_type_ids", None)
generated_ids = model.generate(**inputs, max_new_tokens=8192)
output_text = processor.decode(generated_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False)
print(output_text)感谢你看到这里,添加小助手 AIGC_Tech 加入官方 AIGC读者交流群,下方扫码加入 AIGC Studio 星球,获取前沿AI应用、AIGC实践教程、大厂面试经验、AI学习路线以及IT类入门到精通学习资料等,欢迎一起交流学习💗~
没有评论:
发表评论