IT评测·应用市场-qidao123.com

标题: 13、Ollama OCR [打印本页]

作者: 诗林    时间: 2025-1-11 01:11
标题: 13、Ollama OCR
1、介绍

Ollama OCR,是一个强大的OCR(光学字符识别)工具包。利用 Ollama 的先进视觉语言模型从图像中提取文本,可作为 Python 包和 Streamlit 网络应用步调使用。具有支持多种视觉模型、多种输出格式、批量处置惩罚、图像预处置惩罚等功能。还介绍了安装方法、快速入门示例、输出格式细节以及 Streamlit 网络应用步调的特点。
1.1 多视觉模型支持


1.2 输出格式


1.3 支持批处置惩罚


2、安装测试

2.1 ollama 安装

第一次安装可参考跳转
已安装的测试下是否必要更新
  1. (base) [root@local-staging-x4f7 Ollama-OCR-main]# ollama pull llama3.2-vision:11b
  2. pulling manifest
  3. Error: pull model manifest: 412:
  4. The model you are attempting to pull requires a newer version of Ollama.
  5. Please download the latest version at:
  6.         https://ollama.com/download
复制代码
说明当前版本不支持视觉模型,必要更新。可以参考前面第一次下载的方式重新下载一个新的安装包。
也可以直接下载
  1. curl -L https://ollama.com/download/ollama-linux-amd64.tgz -o ollama-linux-amd64.tgz
  2. sudo tar -xzf ollama-linux-amd64.tgz -C /usr/local/
复制代码

关掉已经开启的服务
  1. (base) [root@local-staging-x4f7 Ollama-OCR-main]# lsof -i :11434
  2. COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
  3. ollama  16778 root    3u  IPv6 39719454      0t0  TCP *:11434 (LISTEN)
  4. (base) [root@local-staging-x4f7 Ollama-OCR-main]# kill 16778
  5. (base) [root@local-staging-x4f7 Ollama-OCR-main]# ollama serve
  6. 2025/01/06 13:50:38 routes.go:1259: INFO server config env="map[CUDA_VISIBLE_DEVICES: GPU_DEVICE_ORDINAL: HIP_VISIBLE_DEVICES: HSA_OVERRIDE_GFX_VERSION: HTTPS_PROXY: HTTP_PROXY: NO_PROXY: OLLAMA_DEBUG:false OLLAMA_FLASH_ATTENTION:false OLLAMA_GPU_OVERHEAD:0 OLLAMA_HOST:http://0.0.0.0:11434 OLLAMA_INTEL_GPU:false OLLAMA_KEEP_ALIVE:5m0s OLLAMA_KV_CACHE_TYPE: OLLAMA_LLM_LIBRARY: OLLAMA_LOAD_TIMEOUT:5m0s OLLAMA_MAX_LOADED_MODELS:0 OLLAMA_MAX_QUEUE:512 OLLAMA_MODELS:/root/.ollama/models OLLAMA_MULTIUSER_CACHE:false OLLAMA_NOHISTORY:false OLLAMA_NOPRUNE:false OLLAMA_NUM_PARALLEL:0 OLLAMA_ORIGINS:[http://localhost https://localhost http://localhost:* https://localhost:* http://127.0.0.1 https://127.0.0.1 http://127.0.0.1:* https://127.0.0.1:* http://0.0.0.0 https://0.0.0.0 http://0.0.0.0:* https://0.0.0.0:* app://* file://* tauri://* vscode-webview://*] OLLAMA_SCHED_SPREAD:false ROCR_VISIBLE_DEVICES: http_proxy: https_proxy: no_proxy:]"
  7. time=2025-01-06T13:50:38.624+08:00 level=INFO source=images.go:757 msg="total blobs: 17"
  8. time=2025-01-06T13:50:38.624+08:00 level=INFO source=images.go:764 msg="total unused blobs removed: 0"
  9. [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
  10. [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
  11. - using env:        export GIN_MODE=release
  12. - using code:        gin.SetMode(gin.ReleaseMode)
  13. [GIN-debug] POST   /api/pull                 --> github.com/ollama/ollama/server.(*Server).PullHandler-fm (5 handlers)
  14. [GIN-debug] POST   /api/generate             --> github.com/ollama/ollama/server.(*Server).GenerateHandler-fm (5 handlers)
  15. [GIN-debug] POST   /api/chat                 --> github.com/ollama/ollama/server.(*Server).ChatHandler-fm (5 handlers)
  16. [GIN-debug] POST   /api/embed                --> github.com/ollama/ollama/server.(*Server).EmbedHandler-fm (5 handlers)
  17. [GIN-debug] POST   /api/embeddings           --> github.com/ollama/ollama/server.(*Server).EmbeddingsHandler-fm (5 handlers)
  18. [GIN-debug] POST   /api/create               --> github.com/ollama/ollama/server.(*Server).CreateHandler-fm (5 handlers)
  19. [GIN-debug] POST   /api/push                 --> github.com/ollama/ollama/server.(*Server).PushHandler-fm (5 handlers)
  20. [GIN-debug] POST   /api/copy                 --> github.com/ollama/ollama/server.(*Server).CopyHandler-fm (5 handlers)
  21. [GIN-debug] DELETE /api/delete               --> github.com/ollama/ollama/server.(*Server).DeleteHandler-fm (5 handlers)
  22. [GIN-debug] POST   /api/show                 --> github.com/ollama/ollama/server.(*Server).ShowHandler-fm (5 handlers)
  23. [GIN-debug] POST   /api/blobs/:digest        --> github.com/ollama/ollama/server.(*Server).CreateBlobHandler-fm (5 handlers)
  24. [GIN-debug] HEAD   /api/blobs/:digest        --> github.com/ollama/ollama/server.(*Server).HeadBlobHandler-fm (5 handlers)
  25. [GIN-debug] GET    /api/ps                   --> github.com/ollama/ollama/server.(*Server).PsHandler-fm (5 handlers)
  26. [GIN-debug] POST   /v1/chat/completions      --> github.com/ollama/ollama/server.(*Server).ChatHandler-fm (6 handlers)
  27. [GIN-debug] POST   /v1/completions           --> github.com/ollama/ollama/server.(*Server).GenerateHandler-fm (6 handlers)
  28. [GIN-debug] POST   /v1/embeddings            --> github.com/ollama/ollama/server.(*Server).EmbedHandler-fm (6 handlers)
  29. [GIN-debug] GET    /v1/models                --> github.com/ollama/ollama/server.(*Server).ListHandler-fm (6 handlers)
  30. [GIN-debug] GET    /v1/models/:model         --> github.com/ollama/ollama/server.(*Server).ShowHandler-fm (6 handlers)
  31. [GIN-debug] GET    /                         --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func1 (5 handlers)
  32. [GIN-debug] GET    /api/tags                 --> github.com/ollama/ollama/server.(*Server).ListHandler-fm (5 handlers)
  33. [GIN-debug] GET    /api/version              --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func2 (5 handlers)
  34. [GIN-debug] HEAD   /                         --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func1 (5 handlers)
  35. [GIN-debug] HEAD   /api/tags                 --> github.com/ollama/ollama/server.(*Server).ListHandler-fm (5 handlers)
  36. [GIN-debug] HEAD   /api/version              --> github.com/ollama/ollama/server.(*Server).GenerateRoutes.func2 (5 handlers)
  37. time=2025-01-06T13:50:38.624+08:00 level=INFO source=routes.go:1310 msg="Listening on [::]:11434 (version 0.5.4)"
复制代码
2.2 下载模型

  1. (base) [root@local-staging-x4f7 szl]# ollama run llama3.2-vision:11b
  2. pulling manifest
  3. pulling 11f274007f09... 100% ▕███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 6.0 GB                        
  4. pulling ece5e659647a... 100% ▕███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 1.9 GB                        
  5. pulling 715415638c9c... 100% ▕███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏  269 B                        
  6. pulling 0b4284c1f870... 100% ▕███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 7.7 KB                        
  7. pulling fefc914e46e6... 100% ▕███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏   32 B                        
  8. pulling fbd313562bb7... 100% ▕███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏  572 B                        
  9. verifying sha256 digest
  10. writing manifest
  11. success
复制代码
2.3 下载源码

  1. git clone git@github.com:imanoop7/Ollama-OCR.git
复制代码
或者下载ZIP文件解压
进入源码文件

  1. (base) [root@local-staging-x4f7 ollama_ocr]# conda create -n ollamaocr python=3.11 -y
复制代码

  1. (base) [root@local-staging-x4f7 ollama_ocr]# conda activate ollamaocr
复制代码

  1. (ollamaocr) [root@local-staging-x4f7 Ollama-OCR-main]# pip install -r requirements.txt
复制代码
2.4 启动情况

  1. (ollamaocr) [root@local-staging-x4f7 Ollama-OCR-main]# cd src/ollama_ocr      
  2. (ollamaocr) [root@local-staging-x4f7 ollama_ocr]# streamlit run app.py
  3. Collecting usage statistics. To deactivate, set browser.gatherUsageStats to false.
  4.   You can now view your Streamlit app in your browser.
  5.   Local URL: http://localhost:8501
  6.   Network URL: http://****:8501
  7.   External URL: http://****:8501
复制代码
2.5 测试

   测试图片

测试效果
  

可以看到英文的识别效果很不错
   中文图片

    识别效果

  效果可以说是惨不忍睹
3、说明

中文识别之以是比较差应该是以下几方面原因

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4