当前位置: 首页 > news >正文

omniparser v2 本地部署及制作docker镜像(20250715)

关于 omniparser v2 本地部署,网上资料不算多,尤其是对于土蔷内用户,还是有些坑的。

1、安装步骤

可参考两个CSDN博客:

(1)大模型实战 - ‘OmniParser-V2本地部署安装  链接

(2)微软开源神器OmniParser-v2.0本地部署教程(更换huggingface镜像服务器)  链接

2、排错

(1)缺 microsoft/Florence-2-base 或其他的一些模型权重,都可以去 modelscope 下载。网站上有下载命令。

(2)提示:

To use Transformers in an offline or firewalled environment requires the downloaded and cached files ahead of time.

根据官方 文档 说明

修改 util/utils.py 文件中

processor = AutoProcessor.from_pretrained("/home/xxxxxxx/OmniParser/microsoft/Florence-2-base", local_files_only=True,trust_remote_code=True)

主要是把 microsoft/Florence-2-base 这个模型名换成具体的文件路径,并设置 trust_remote_code=True

(3)更换镜像(可选)

刚才提到的文章:微软开源神器OmniParser-v2.0本地部署教程(更换huggingface镜像服务器)(链接),其中提到更换镜像,对于不熟悉的人来说,可能不知道作者在说什么。这里补充:

其实是更换huggingface镜像服务器:

位置:transformers/constants.py

(例如:~/.local/lib/python3.10/site-packages/transformers/constants.py)

位置:huggingface_hub/constants.py

(例如:~/.local/lib/python3.10/site-packages/huggingface_hub/constants.py)

(4)错误:

Please check your internet connection. This can happen if your antivirus software blocks the download of this file. You can install manually by following these steps:

1. Download this file: https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm64

2. Rename the downloaded file to: frpc_linux_arm64_v0.3

3. Move the file to this location: /home/xxxxxx/miniconda3/envs/omni/lib/python3.12/site-packages/gradio

gitee上有 frpc_linux_arm64 这个文件,可以去下载。然后按照提示改名、移动位置、增加权限:

chmod +x /home/xxxx/miniconda3/envs/omni/lib/python3.12/site-packages/gradio/frpc_linux_arm64_v0.3

(5)提示:

TypeError: argument of type 'bool' is not iterable

Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.

改 gradio_demo.py 文件的下面一行代码

demo.launch(share=False, server_port=7861, server_name='0.0.0.0')

设置share=False

(6)提示:

Florence2ForConditionalGeneration.forward() got an unexpected keyword argument 'images'

定位 util/utils.py 文件中

model = AutoModelForCausalLM.from_pretrained(model_name_or_path, torch_dtype=torch.float32, trust_remote_code=True)

前面加一句:

model_name_or_path="/home/xxxxxx/OmniParser/microsoft/Florence-2-base-ft"

因为前面代码有默认设置:

model_name_or_path="Salesforce/blip2-opt-2.7b"

3、构建 docker 镜像

(1)先用豆包将 gradio_demo.py 改成接收 http 请求的服务器。

from typing import Optional
import base64
import io
import os
from flask import Flask, request, jsonify
from PIL import Image
import numpy as np
import torch
from util.utils import check_ocr_box, get_yolo_model, get_caption_model_processor, get_som_labeled_imgapp = Flask(__name__)yolo_model = get_yolo_model(model_path='weights/icon_detect/model.pt')
caption_model_processor = get_caption_model_processor(model_name="florence2", model_name_or_path="weights/icon_caption_florence")
# caption_model_processor = get_caption_model_processor(model_name="blip2", model_name_or_path="weights/icon_caption_blip2")DEVICE = torch.device('cuda')def process(image_input,box_threshold,iou_threshold,use_paddleocr,imgsz
) -> Optional[Image.Image]:box_overlay_ratio = image_input.size[0] / 3200draw_bbox_config = {'text_scale': 0.8 * box_overlay_ratio,'text_thickness': max(int(2 * box_overlay_ratio), 1),'text_padding': max(int(3 * box_overlay_ratio), 1),'thickness': max(int(3 * box_overlay_ratio), 1),}ocr_bbox_rslt, is_goal_filtered = check_ocr_box(image_input, display_img=False, output_bb_format='xyxy',goal_filtering=None, easyocr_args={'paragraph': False,'text_threshold': 0.9},use_paddleocr=use_paddleocr)text, ocr_bbox = ocr_bbox_rsltdino_labled_img, label_coordinates, parsed_content_list = get_som_labeled_img(image_input, yolo_model,BOX_TRESHOLD=box_threshold,output_coord_in_ratio=True,ocr_bbox=ocr_bbox,draw_bbox_config=draw_bbox_config,caption_model_processor=caption_model_processor,ocr_text=text,iou_threshold=iou_threshold,imgsz=imgsz)image = Image.open(io.BytesIO(base64.b64decode(dino_labled_img)))print('finish processing')parsed_content_list = '\n'.join([f'icon {i}: ' + str(v) for i, v in enumerate(parsed_content_list)])return image, str(parsed_content_list)@app.route('/process_image', methods=['POST'])
def process_image():try:# 获取图像数据file = request.files['image']image = Image.open(file.stream)# 获取参数box_threshold = float(request.form.get('box_threshold', 0.05))iou_threshold = float(request.form.get('iou_threshold', 0.1))use_paddleocr = bool(request.form.get('use_paddleocr', True))imgsz = int(request.form.get('imgsz', 640))# 处理图像processed_image, parsed_content = process(image, box_threshold, iou_threshold, use_paddleocr, imgsz)# 将处理后的图像转换为 base64 编码buffered = io.BytesIO()processed_image.save(buffered, format="PNG")img_str = base64.b64encode(buffered.getvalue()).decode()# 返回结果return jsonify({'image': img_str,'parsed_content': parsed_content})except Exception as e:return jsonify({'error': str(e)}), 500if __name__ == '__main__':app.run(host='0.0.0.0', port=7861)

可以运行测试代码:

curl -X POST \-F "image=@path/to/your/image.jpg" \-F "box_threshold=0.05" \-F "iou_threshold=0.1" \-F "use_paddleocr=true" \-F "imgsz=640" \http://localhost:7861/process_image

(2)创建 dockerfile (放在 omniparser 文件夹下)

# 使用 Python 3.12 作为基础镜像
FROM python:3.12-slim# 设置工作目录
WORKDIR /app# 安装系统依赖
RUN apt-get update && apt-get install -y \git \curl \wget \unzip \&& rm -rf /var/lib/apt/lists/*# 复制项目文件
COPY . /app# 安装 Python 依赖
RUN pip install --no-cache-dir -r requirements.txt# 解压权重文件(如果需要)
RUN if [ -f "omniparse_weights.zip" ]; then unzip omniparse_weights.zip -d weights; fi# 暴露应用端口(根据实际应用修改)
EXPOSE 7861 # 设置环境变量(根据需要添加)
ENV PYTHONPATH="/app:$PYTHONPATH"# 定义启动命令(根据实际应用修改)
CMD ["python", "flask_demo.py"]

(3)运行docker可能需要设置镜像

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://docker.xuanyuan.me/"]
}
EOF

重启 Docker 服务:

sudo systemctl daemon-reload
sudo systemctl restart docker

测试一下:

docker run hello-world

(4)构建 docker 镜像

# 构建镜像
docker build -t omniparser:latest .# 运行容器(前台模式)
docker run -it --rm -p 7861:7861 -p 5000:5000 omniparser:latest# 或使用后台模式
docker run -d -p 7861:7861 --name omniparser omniparser:latest


文章转载自:
http://bicephalous.zzyjnl.cn
http://chiller.zzyjnl.cn
http://bottomland.zzyjnl.cn
http://cafetorium.zzyjnl.cn
http://beachy.zzyjnl.cn
http://calydonian.zzyjnl.cn
http://borecole.zzyjnl.cn
http://allahabad.zzyjnl.cn
http://catalanist.zzyjnl.cn
http://almacantar.zzyjnl.cn
http://anjou.zzyjnl.cn
http://ceremonialize.zzyjnl.cn
http://behoof.zzyjnl.cn
http://adaption.zzyjnl.cn
http://agleam.zzyjnl.cn
http://antiviral.zzyjnl.cn
http://camphire.zzyjnl.cn
http://beshow.zzyjnl.cn
http://bluethroat.zzyjnl.cn
http://aidedecamp.zzyjnl.cn
http://cannabinoid.zzyjnl.cn
http://batman.zzyjnl.cn
http://arrect.zzyjnl.cn
http://catafalque.zzyjnl.cn
http://boatyard.zzyjnl.cn
http://beverley.zzyjnl.cn
http://arigato.zzyjnl.cn
http://adeodatus.zzyjnl.cn
http://atomism.zzyjnl.cn
http://cherubic.zzyjnl.cn
http://www.dtcms.com/a/280408.html

相关文章:

  • 从浏览器到服务器:TCP 段的网络传输之旅
  • 设计模式二:策略模式 (Strategy Pattern)
  • 云计算如何提高企业的数据安全性和隐私保护
  • 我会秘书长杨添天带队赴杭州融量农业发展有限公司考察调研
  • NQTT-基础知识
  • CSS :root伪类详解:实现动态主题切换的关键所在
  • 7.15 Java基础|大小写转换、数组、ArrayList类
  • 基于Langchain4j开发AI编程助手
  • Python_1
  • 高等数学强化——导学
  • 【Python练习】044. 编写一个函数,实现快速排序算法
  • 第十三讲 | map和set的使用
  • JavaDemo——使用CGLIB动态代理
  • I3C通信驱动开发注意事项
  • 【雅思播客016】New Year Resolution 新年决心
  • docker搭建freeswitch实现点对点视频,多人视频
  • 极致cms多语言建站|设置主站默认语言与设置后台固定语言为中文
  • 嵌入式学习-PyTorch(4)-day21
  • 多相机depth-rgb图组完整性分拣器_MATLAB实现
  • @[TOC](模拟) # 1.替换所有的问号(easy)
  • 学C++做游戏,先搞懂这些基础要点
  • 《大数据技术原理与应用》实验报告六 Flink编程实践
  • 使用JS编写用户信息采集表单
  • 【Python3-Django】快速掌握DRF:ModelViewSet实战指南
  • OneCode 3.0 从0到1干货——AIGC及MCP注解驱动开发物联网AI决策应用
  • 全新 Python 项目托管到 Gitee 私有仓库完整流程(带详细命令注释)
  • OpenVINO initialization error: Failed to find plugins.xml file
  • uv 使用指导文档
  • 【机器学习深度学习】LoRA 微调详解:大模型时代的高效适配利器
  • BlueLotus XSS管理后台使用指南