微软开源神器OmniParser-v2.0本地部署教程

news/2025/2/26 5:22:30

安装python环境

我这里是以前安装好的版本:python 3.11.5,这里不再介绍,有需要的可以在网上找教程。

安装Anaconda

我这里是以前安装好的版本:conda 23.7.4,这里也不再介绍,有需要的可以在网上找教程。

安装OmniParser

git clone https://github.com/microsoft/OmniParser.git
cd OmniParser

创建专属环境

conda create -n "omni" python==3.11
conda activate omni

执行下面命令,下载所需要的依赖包。

pip install -r requirements.txt

下载 microsoft/OmniParser-v2.0 模型文件,但是一直进不去网址(https://huggingface.co),所以我选择了https://hf-mirror.com/。

在这里插入图片描述

找到microsoft/OmniParser-v2.0

在这里插入图片描述

进去之后点击icon_caption和icon_detect)文件夹,分别下载里面文件。

在这里插入图片描述

主要为下面6个文件。

icon_detect/train_args.yaml
icon_detect/model.pt
icon_detect/model.yaml
icon_caption/config.json
icon_caption/generation_config.json
icon_caption/model.safetensors

在项目目录下新建目录,具体如下

mkdir -p weights/icon_detect
mkdir -p weights/icon_caption_florence

完成效果如下:

在这里插入图片描述

将前面下载好的文件分别对应的文件夹。

在这里插入图片描述

运行 python gradio_demo.py 命令,稍等之后出现如下面报错。

[2025-02-25 20:11:26,669] [ WARNING] easyocr.py:80 - Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU.
Traceback (most recent call last):
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connection.py", line 203, in _new_conn
    sock = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    raise err
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
    sock.connect(sa)
TimeoutError: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connectionpool.py", line 491, in _make_request
    raise new_e
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connectionpool.py", line 1096, in _validate_conn
    conn.connect()
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connection.py", line 611, in connect
    self.sock = sock = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connection.py", line 212, in _new_conn
    raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x0000019B3B7505D0>, 'Connection to huggingface.co timed out. (connect timeout=10)')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\DevelopmentTools\Python\Lib\site-packages\requests\adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\urllib3\util\retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /microsoft/Florence-2-base/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000019B3B7505D0>, 'Connection to huggingface.co timed out. (connect timeout=10)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\file_download.py", line 1376, in _get_metadata_or_catch_error
    metadata = get_hf_file_metadata(
               ^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\file_download.py", line 1296, in get_hf_file_metadata
    r = _request_wrapper(
        ^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\file_download.py", line 280, in _request_wrapper
    response = _request_wrapper(
               ^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\file_download.py", line 303, in _request_wrapper
    response = get_session().request(method=method, url=url, **params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\utils\_http.py", line 96, in send
    return super().send(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\requests\adapters.py", line 507, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /microsoft/Florence-2-base/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000019B3B7505D0>, 'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: 3ae795ae-e87f-45e3-8c1b-26c359494139)')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\DevelopmentTools\Python\Lib\site-packages\transformers\utils\hub.py", line 342, in cached_file
    resolved_file = hf_hub_download(
                    ^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\file_download.py", line 862, in hf_hub_download
    return _hf_hub_download_to_cache_dir(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\file_download.py", line 969, in _hf_hub_download_to_cache_dir
    _raise_on_head_call_error(head_call_error, force_download, local_files_only)
  File "D:\DevelopmentTools\Python\Lib\site-packages\huggingface_hub\file_download.py", line 1489, in _raise_on_head_call_error
    raise LocalEntryNotFoundError(
huggingface_hub.errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\OmniParser\gradio_demo.py", line 16, in <module>
    caption_model_processor = get_caption_model_processor(model_name="florence2", model_name_or_path="weights/icon_caption_florence")
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\OmniParser\util\utils.py", line 63, in get_caption_model_processor
    processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\transformers\models\auto\processing_auto.py", line 305, in from_pretrained
    config = AutoConfig.from_pretrained(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\transformers\models\auto\configuration_auto.py", line 1075, in from_pretrained
    config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\transformers\configuration_utils.py", line 594, in get_config_dict
    config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\transformers\configuration_utils.py", line 653, in _get_config_dict
    resolved_config_file = cached_file(
                           ^^^^^^^^^^^^
  File "D:\DevelopmentTools\Python\Lib\site-packages\transformers\utils\hub.py", line 385, in cached_file
    raise EnvironmentError(
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like microsoft/Florence-2-base is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.

看着错误很多,其实就是 https://huggingface.co 访问不到的原因。我们将constants.py文件里的 https://huggingface.co 替换为https://hf-mirror.com。

在这里插入图片描述

为此,还是不放心,网上找了教程,又在最前面加了一行设置。

在这里插入图片描述

再次输入 python gradio_demo.py 命令,运行成功如下图所示:

在这里插入图片描述

在浏览器输入:http://127.0.0.1:7861,显示结果如下:

在这里插入图片描述

截一张桌面的图,让他进行分析:

在这里插入图片描述
END

毋庸置疑,好的事情总会到来。而当它来晚时,也不失为一种惊喜。


http://www.niftyadmin.cn/n/5868029.html

相关文章

wifi5和wifi6,WiFi 2.4G、5G,五类网线和六类网线,4G和5G的区别

wifi5和wifi6的区别 是Wi-Fi 5和Wi-Fi 6的选择与路由器密切相关。路由器是创建和管理无线网络的设备,它决定了网络的类型和性能。具体来说: 路由器的标准支持:路由器可以支持不同的Wi-Fi标准,如Wi-Fi 5(802.11ac)和Wi-Fi 6(802.11ax)。支持Wi-Fi 6的路由器能够提供更高…

Node.js定义以及性能优化

Node.js Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时&#xff0c;广泛用于构建高性能的网络应用。以下是一些常见的 Node.js 面试题及其解答&#xff0c;帮助你准备面试&#xff1a; 1. 什么是 Node.js&#xff1f; Node.js 是一个基于 Chrome V8 引擎的 JavaSc…

神经网络发展简史:从感知机到通用智能的进化之路

引言 神经网络作为人工智能的核心技术&#xff0c;其发展历程堪称一场人类对生物大脑的致敬与超越。本文将用"模型进化"的视角&#xff0c;梳理神经网络发展的五大关键阶段&#xff0c;结合具象化比喻和经典案例&#xff0c;为读者呈现一幅清晰的AI算法发展图谱。 一…

《百度蜘蛛池:提升网站收录的关键利器》

Tbaidutopseo(蜘蛛池.中国) 在互联网的浩瀚世界中&#xff0c;网站如同繁星般众多&#xff0c;如何让自己的网站脱颖而出&#xff0c;获得更多的流量和曝光&#xff0c;是每一位网站所有者都在思考的问题。而网站收录&#xff0c;作为网站在搜索引擎中展示的基础&#xff0c;其…

JavaWeb 学习笔记

前端基础 HTML-CSS <!doctype html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport"content"widthdevice-width, user-scalableno, initial-scale1.0, maximum-scale1.0, minimum-scale1.0…

[特殊字符] 蓝桥杯 Java B 组 之最小生成树(Prim、Kruskal) 并查集应用

Day 3&#xff1a;最小生成树&#xff08;Prim、Kruskal&#xff09; & 并查集应用 &#x1f4d6; 一、最小生成树&#xff08;MST&#xff09;简介 最小生成树&#xff08;Minimum Spanning Tree, MST&#xff09; 是一个 无向连通图 的 最小代价子图&#xff0c;它包含 …

django 的值有正确的格式 (YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) 但它是一个错误的日期/时间‘

好的&#xff0c;我将根据你的要求来回答关于Django中日期时间格式的问题。 报错问题解释 在Django中&#xff0c;如果你在处理日期时间字段时遇到了错误&#xff0c;通常是因为你尝试将一个不符合Django期望格式的字符串或值赋给日期时间字段。Django的日期时间字段期望的格式…

rust安装教程以及git连接到远程仓库

1.官方网站下载rustup-init程序 链接: rust-lang 从这里可以获取到rust的下载程序,这个下载程序会帮助你下载visual-studio的安装包从而获取相关的编译环境。 tips:无需再下载visual_studio 2确认安装所需要的框架&#xff0c;SKD工具 安装完毕之后可以检查一下 rustc --ve…