Llama 3.2-Vision 是一种多模态大型语言模型,有 11B 和 90B 两种大小,能够处理文本和图像输入,生成文本输出。该模型在视觉识别、图像推理、图像描述和回答图像相关问题方面表现出色,在多个行业基准测试中均优于现有的开源和闭源多模态模型。

本文将介绍开源的 ollama-ocr[1] 工具,它默认使用本地运行的 Llama 3.2-Vision 视觉模型,可准确识别图像中的文字,同时保留原始格式。

https://github.com/bytefer/ollama-ocr

Ollama-OCR 的特点

  • 使用 Llama 3.2-Vision 模型进行高精度文本识别 保留原始文本格式和结构
  • 支持多种图像格式:JPG、JPEG、PNG
  • 可定制的识别提示和模型
  • Markdown 输出格式选项

Llama 3.2-Vision 应用场景

识别手写文本

图片

OCR 识别

图片

图片问答

图片

配置环境

安装 Ollama

在开始使用 Llama 3.2-Vision 之前,您需要安装 Ollama[2],这是一个支持在本地运行多模态模型的平台。请按照以下步骤安装:

1. 下载 Ollama:访问 Ollama 官方网站,下载适用于您操作系统的安装包。

图片

2. 安装 Ollama:根据下载的安装包,按照提示完成安装。

安装 Llama 3.2-Vision 11B

安装 Ollama 后,可使用以下命令安装 Llama 3.2-Vision 11B[3]

ollama run llama3.2-vision

安装 Ollama-OCR

npm install ollama-ocr # or using pnpm pnpm add ollama-ocr

使用 Ollama-OCR

OCR

import { ollamaOCR, DEFAULT_OCR_SYSTEM_PROMPT } from "ollama-ocr"; async function runOCR({
  const text = await ollamaOCR({
    filePath: "./handwriting.jpg",
    systemPrompt: DEFAULT_OCR_SYSTEM_PROMPT,
  });
  console.log(text);
}

测试的图片如下:

图片

输出的结果如下:

The Llama 3.2-Vision collection of multimodal large language models (LLMs) is a collection of instruction-tuned image reasoning generative models in 118 and 908 sizes (text + images in / text out). The Llama 3.2-Vision instruction-tuned models are optimized for visual recognition, image reasoning, captioning, and answering general questions about an image. The models outperform many of the available open source and closed multimodal models on common industry benchmarks.

输出 Markdown

import { ollamaOCR, DEFAULT_MARKDOWN_SYSTEM_PROMPT } from "ollama-ocr"; async function runOCR({
  const text = await ollamaOCR({
    filePath: "./trader-joes-receipt.jpg",
    systemPrompt: DEFAULT_MARKDOWN_SYSTEM_PROMPT,
  });
  console.log(text);
}

测试的图片如下: 

图片

输出的结果如下:

图片

ollama-ocr 使用的本地的视觉模型,如果你想使用线上的 Llama 3.2-Vision 模型,可以试试 llama-ocr[4] 这个库。

点赞(0) 打赏
立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部