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

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

1、安装步骤

可参考两个CSDN博客:

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

(2)微软开源神器OmniParser-v2.0本地部署教程  链接

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镜像服务器:

位置: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://www.pswp.cn/pingmian/89138.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/89138.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

自己写个 `rsync` + `fswatch` 实时增量同步脚本,干掉 Cursor AI、Sublime Text 的SFTP等 插件!

自己写个 rsync fswatch 实时增量同步脚本&#xff0c;干掉 Cursor AI、Sublime Text 的 SFTP等 插件&#xff01; 作为一个码农&#xff0c;我最头疼的事情之一就是编辑器同步代码到服务器这块。用过各种各样的sftp、rsync插件&#xff0c;感觉不好用。。 我琢磨着&#xff1…

linux中at命令的常用用法。

Linux 中 at 命令用于安排一次性定时任务&#xff0c;需要用到在某个时间只需要执行一次的命令的时候&#xff0c;可以使用at 1&#xff1a;安装at # Debian/Ubuntu sudo apt install at# CentOS/RHEL sudo yum install at2&#xff1a;启动at sudo systemctl start atd # 启…

【安卓笔记】RxJava的使用+修改功能+搭配retrofit+RxView防快速点击

0. 环境&#xff1a; 电脑&#xff1a;Windows10 Android Studio: 2024.3.2 编程语言: Java Gradle version&#xff1a;8.11.1 Compile Sdk Version&#xff1a;35 Java 版本&#xff1a;Java11 1. 介绍RxJava GitHub开源地址&#xff1a;https://github.com/Reactive…

Windows 下原生使用 claude code + Kimi K2

搞定了kimi k2 claude code在windows下原生使用 Windows下使用claude code的障碍是shell环境&#xff08;命令行&#xff09;&#xff0c;非posix风格shell无法正常让claude code读取到url和key, 导致无法使用。解决问题的本质是使用符合posix风格的shell环境&#xff0c;我们…

Leetcode Easy题小解(C++语言描述)1

Leetcode Easy题小解&#xff08;C语言描述&#xff09; 相交链表 给你两个单链表的头节点 headA 和 headB &#xff0c;请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点&#xff0c;返回 null 。 图示两个链表在节点 c1 开始相交**&#xff1a;**题目数据…

EP01:【NLP 第二弹】自然语言处理概述

一、NLP通向智能之路 1.1 图灵测试 1.1.1 提出背景 由计算机科学家阿兰・图灵于 1950 年提出&#xff0c;是早期衡量机器智能水平的重要概念。 1.1.2 提出目的 判断机器是否能表现出与人类相当的智能行为。 1.1.3 测试原理 场景设定&#xff1a;测试中存在一位人类测试者&#…

Ansible 查看PostgreSQL的版本

Ansible的基础知识就不说了直接贴剧本- name: Check PostgreSQL versionhosts: db_serversbecome: yesvars:ansible_python_interpreter: /usr/bin/python3db_name: postgresdb_user: postgresdb_password: your_passwordtasks:- name: Install psycopg2ansible.builtin.packag…

【视觉SLAM笔记】第9章 后端1

一、理论1. 状态估计的概率解释我们来深入探讨一下视觉SLAM中状态估计的概率解释。这可以说是理解现代SLAM算法&#xff08;尤其是后端优化&#xff09;的基石1. 问题的核心&#xff1a;不确定性SLAM&#xff08;同步定位与建图&#xff09;的本质是在一个未知环境中&#xff0…

(数据结构)复杂度

基本概念说明 数据结构 定义&#xff1a;数据结构(Data Structure)是计算机存储、组织数据的方式&#xff0c;指相互之间存在⼀种或多种特定关系的数据元素的集合。没有⼀种单⼀的数据结构对所有用途都有用&#xff08;要考虑适配、效率问题&#xff0c;在不同情况下使用合适的…

玩转Docker | 使用Docker部署bender个人导航页工具

玩转Docker | 使用Docker部署bender个人导航页工具 前言 一、bender介绍 Bender 简介 Bender 的主要特点 二、系统要求 环境要求 环境检查 Docker版本检查 检查操作系统版本 三、部署bender服务 下载bender镜像 编辑部署文件 创建容器 检查容器状态 检查服务端口 安全设置 四、…

解决了困扰我的upload靶场无法解析phtml等后缀的问题

本文章为解决困扰我的 upload 靶场无法解析 phtml 问题 ​ 这个问题直接让我过不了Upload-Pass-03这一关&#xff0c;一直卡着。 ​ 痛太痛了 &#xff0c;为什么无法解析上传之后的 phtml 后缀文件&#xff01;这块儿折磨了博主一天多&#xff0c;太不容易了&#xff0c;查找…

Leetcode百题斩-二分搜索

二分搜索也是一个很有趣的专题&#xff0c;被做过的题中&#xff0c;刚好一个Easy&#xff0c;一个Medium和一个Hard&#xff0c;刚好可以看看&#xff0c;二分搜索的三个难度等级都是啥样的。 124. Binary Tree Maximum Path Sum[Hard]&#xff08;详见二叉树专题&#xff09;…

【IDEA】格式化代码工具配置

格式化代码快捷键&#xff1a; CtrlAltL格式代码的时候不会再方法名与参数中间添加空格默认不勾选的情况下&#xff1a;代码样例&#xff1a;勾选之后的样例&#xff1a;选择不勾选&#xff0c;IDEA默认情况下就是不勾选的状态忽略加载文件有些非必要加载到开发工具中的文件我们…

驱动开发(3)|rk356x驱动GPIO基础应用之点亮led灯

点亮LED灯看似是一个基础的操作&#xff0c;但实际上&#xff0c;许多高级应用也依赖于高低电平的切换。例如&#xff0c;脉冲宽度调制&#xff08;PWM&#xff09;信号可以用来精确控制电机的转速&#xff0c;通过改变脉冲的频率和占空比&#xff0c;实现对电机的精确调节&…

手动搭建PHP环境:步步为营,解锁Web开发

目录一、引言二、准备工作2.1 明确所需软件2.2 下载软件三、Windows 系统搭建步骤3.1 安装 Apache 服务器3.2 安装 PHP3.3 集成 Apache 与 PHP3.4 安装 MySQL3.5 配置 PHP 连接 MySQL四、Linux 系统搭建步骤&#xff08;以 Ubuntu 为例&#xff09;4.1 更新系统4.2 安装 Apache…

DrissionPage:一款让网页自动化更简单的 Python 库

在网页自动化领域&#xff0c;Selenium 和 Playwright 早已是开发者耳熟能详的工具。但今天要给大家介绍一款更轻量、更易用的 Python 库 ——DrissionPage。它以 "融合 selenium 和 requests 优势" 为核心设计理念&#xff0c;既能像 requests 一样高效处理静态网页…

理解Grafana中`X-Scope-OrgID`的作用与配置

X-Scope-OrgID的作用 该HTTP Header用于标识Loki日志数据的所属租户&#xff08;组织&#xff09;。在多租户模式下&#xff0c;Loki通过此Header隔离不同团队或用户的数据&#xff0c;确保查询和存储的独立性。数据隔离&#xff1a; 租户A的日志标记为X-Scope-OrgID: team-a&a…

【PycharmPyqt designer桌面程序设计】

在 main.py 中调用 Qt Designer 生成的 windows.py&#xff08;假设它是 PySide2 版&#xff09;。 只要把两个文件放在同一目录即可直接运行。 ──────────────────── 1️⃣ windows.py&#xff08;Qt Designer 生成&#xff0c;已转码&#xff09; # -*-…

Unity Android Logcat插件 输出日志中文乱码解决

背景之前安卓真机调试看日志&#xff0c;一直用的是Android Studio自带的adb命令进行看日志&#xff0c;不太方便&#xff0c;改用Unity自带的安卓日志插件时&#xff0c;存在中文日志乱码问题。插件安装基于Unity6000.1.11版本&#xff1a;Window -> Package Management -&…

Halcon双相机单标定板标定实现拼图

1.Halcon图像拼接算法在之前的文章里也写过&#xff0c;主要是硬拼接和特征点拼接两种方式&#xff0c;今天增加另一种拼接图像的方式。应用场景是多个相机联合一起拍大尺寸的物体&#xff0c;并且相机视野之间存在重叠区域。通过在同一个标定板上面标定&#xff0c;计算两个相…