ComfyUI - ComfyUI 工作流中集成 SAM2 + GroundingDINO 处理图像与视频 教程

news2024/11/7 1:18:25

欢迎关注我的CSDN:https://spike.blog.csdn.net/
本文地址:https://spike.blog.csdn.net/article/details/143359538

免责声明:本文来源于个人知识与公开资料,仅用于学术交流,欢迎讨论,不支持转载。


SAM2

SAM2 与 GroundingDINO 结合,在图像分割和目标检测领域带来显著的进展,SAM2 实现精确的图像分割,而 GroundingDINO 则强化模型的目标检测能力,提供更加准确和细致的物体识别。在实际应用中,能够有效提升各类复杂图像处理任务的性能,协同工作提高处理速度,还确保高精度和稳定性。

ComfyUI 部署节点的 3 个步骤:

  1. 准备 节点(Node) 工程,git clone,位于 ComfyUI/custom_nodes
  2. 安装依赖包,进入工程,运行 pip install -r requirements.txt
  3. (可选) 模型提前下载,放入相应的文件夹中
  4. 重启服务,刷新页面,即可运行。

下载工程:ComfyUI-segment-anything-2、ComfyUI-Florence2、ComfyUI-KJNodes、ComfyUI-SAM2、ComfyUI-VideoHelperSuite

cd ComfyUI/custom_nodes

git clone https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git
git clone https://github.com/kijai/ComfyUI-segment-anything-2.git
git clone https://github.com/kijai/ComfyUI-Florence2.git
git clone https://github.com/kijai/ComfyUI-KJNodes.git

# v1.0 版本,被 ComfyUI-SAM2替代
# git clone https://github.com/storyicon/comfyui_segment_anything 
git clone https://github.com/neverbiasu/ComfyUI-SAM2.git

pip install -r requirements.txt

1.ComfyUI-segment-anything-2

节点:ComfyUI-segment-anything-2

准备模型:

  1. SAM2 模型 - ComfyUI/models/sam2
  2. Florence-2 模型ComfyUI/models/LLM,用于代替检测模型,例如 GroundingDINO,参考 ComfyUI-Florence2

支持处理视频流程,但是整体分割效果非常一般,而且 Points 效果也比较一般。

依赖节点:ComfyUI-Florence2、ComfyUI-KJNodes、ComfyUI-VideoHelperSuite

测试示例位于:https://github.com/kijai/ComfyUI-segment-anything-2/tree/main/examples

例如:points_segment_video_example.json

  • Load Video (Upload),加载视频节点
  • Points Editor,Point 编辑节点,使用 shift + 左右键,选择正负点。
  • (Down)Load SAM2Model,下载或加载模型,sam2.1_hiera_large-fp16.safetensors,选择 fp16
  • Sam2Segmentation 分割节点,注意,需要重新添加,默认流程有问题,接受正负点。
  • Preview Animation 显示动画效果

即:
Img

2.ComfyUI-SAM2

节点:ComfyUI-SAM2

准备模型:models/bert-base-uncasedmodels/grounding-dinomodels/sams

GroundingDino + SAM2,只有 3 个节点,功能比较单一,检测效果较好。

  • GroundingDinoModelLoader (segment anything2),加载 DINO 模型
  • SAM2ModelLoader (segment anything2),加载 SAM2 模型
  • GroundingDinoSAM2Segment (segment anything2),合并,只有2个参数,Prompt 和 阈值

测试模型效果,支持多个词汇,例如 person 和 book,注意逗号分割,即:

Img

效果如下:

SAM2


Workflow1:

{"last_node_id":117,"last_link_id":62,"nodes":[{"id":113,"type":"Note","pos":{"0":56,"1":-415},"size":{"0":309.1065368652344,"1":177.01339721679688},"flags":{},"order":0,"mode":0,"inputs":[],"outputs":[],"properties":{"text":""},"widgets_values":["To get the image for the points editor, first create a canvas, then either input image/video (first frame is taken), or copy/paste an image while the node is selected, or drag&drop an image.\n\nWARNING: the image WILL BE SAVED to the node in compressed format, including when saving the workflow!\n\nClick the ? on the node for more information"],"color":"#432","bgcolor":"#653"},{"id":116,"type":"Reroute","pos":{"0":1066,"1":115},"size":[75,26],"flags":{},"order":5,"mode":0,"inputs":[{"name":"","type":"*","link":60,"label":"","widget":{"name":"value"}}],"outputs":[{"name":"","type":"STRING","links":[61],"slot_index":0,"label":""}],"properties":{"showOutputText":false,"horizontal":false}},{"id":112,"type":"ShowText|pysssss","pos":{"0":1166,"1":-429},"size":{"0":315,"1":100},"flags":{},"order":4,"mode":0,"inputs":[{"name":"text","type":"STRING","link":53,"widget":{"name":"text"},"label":"text"}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6,"label":"STRING"}],"properties":{"Node name for S&R":"ShowText|pysssss"},"widgets_values":["","[{\"x\": 256, \"y\": 256}, {\"x\": 237, \"y\": 463}, {\"x\": 321, \"y\": 138}]"]},{"id":117,"type":"ShowText|pysssss","pos":{"0":1163,"1":-277},"size":{"0":315,"1":76},"flags":{},"order":6,"mode":0,"inputs":[{"name":"text","type":"STRING","link":62,"widget":{"name":"text"},"label":"text"}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6,"label":"STRING"}],"properties":{"Node name for S&R":"ShowText|pysssss"},"widgets_values":["","[{\"x\": 0, \"y\": 0}, {\"x\": 426, \"y\": 242}]"]},{"id":102,"type":"VHS_LoadVideo","pos":{"0":14,"1":-59},"size":[363.24957275390625,619.2495727539062],"flags":{},"order":1,"mode":0,"inputs":[{"name":"meta_batch","type":"VHS_BatchManager","link":null,"shape":7,"label":"meta_batch"},{"name":"vae","type":"VAE","link":null,"shape":7,"label":"vae"}],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[43,52,57],"slot_index":0,"shape":3,"label":"IMAGE"},{"name":"frame_count","type":"INT","links":null,"shape":3,"label":"frame_count"},{"name":"audio","type":"AUDIO","links":null,"shape":3,"label":"audio"},{"name":"video_info","type":"VHS_VIDEOINFO","links":null,"shape":3,"label":"video_info"}],"properties":{"Node name for S&R":"VHS_LoadVideo"},"widgets_values":{"video":"2851_1708350515(原视频).mp4","force_rate":0,"force_size":"512x?","custom_width":512,"custom_height":512,"frame_load_cap":16,"skip_first_frames":0,"select_every_nth":3,"choose video to upload":"image","videopreview":{"hidden":false,"paused":false,"params":{"frame_load_cap":16,"skip_first_frames":0,"force_rate":0,"filename":"2851_1708350515(原视频).mp4","type":"input","format":"video/mp4","select_every_nth":3,"force_size":"512x?"}}}},{"id":114,"type":"PointsEditor","pos":{"0":439,"1":-477},"size":[557,812],"flags":{"collapsed":false},"order":3,"mode":0,"inputs":[{"name":"bg_image","type":"IMAGE","link":52,"shape":7,"label":"bg_image"}],"outputs":[{"name":"positive_coords","type":"STRING","links":[53,55],"slot_index":0,"shape":3,"label":"positive_coords"},{"name":"negative_coords","type":"STRING","links":[60,62],"slot_index":1,"shape":3,"label":"negative_coords"},{"name":"bbox","type":"BBOX","links":null,"slot_index":2,"shape":3,"label":"bbox"},{"name":"bbox_mask","type":"MASK","links":null,"shape":3,"label":"bbox_mask"},{"name":"cropped_image","type":"IMAGE","links":null,"shape":3,"label":"cropped_image"}],"properties":{"Node name for S&R":"PointsEditor","imgData":{"name":"bg_image","base64":[""]},"points":"PointsEditor","neg_points":"PointsEditor"},"widgets_values":["{\"positive\":[{\"x\":256,\"y\":256},{\"x\":237,\"y\":463},{\"x\":321,\"y\":138}],\"negative\":[{\"x\":0,\"y\":0},{\"x\":426,\"y\":242}]}","[{\"x\":256,\"y\":256},{\"x\":237,\"y\":463},{\"x\":321,\"y\":138}]","[{\"x\":0,\"y\":0},{\"x\":426,\"y\":242}]","[{}]","[{}]","xyxy",512,512,false,null,null,null]},{"id":106,"type":"DownloadAndLoadSAM2Model","pos":{"0":459,"1":393},"size":{"0":315,"1":130},"flags":{},"order":2,"mode":0,"inputs":[],"outputs":[{"name":"sam2_model","type":"SAM2MODEL","links":[56],"shape":3,"label":"sam2_model"}],"properties":{"Node name for S&R":"DownloadAndLoadSAM2Model"},"widgets_values":["sam2.1_hiera_large.safetensors","video","cuda","fp16"]},{"id":115,"type":"Sam2Segmentation","pos":{"0":898,"1":393},"size":{"0":315,"1":190},"flags":{},"order":7,"mode":0,"inputs":[{"name":"sam2_model","type":"SAM2MODEL","link":56,"label":"sam2_model"},{"name":"image","type":"IMAGE","link":57,"label":"image"},{"name":"bboxes","type":"BBOX","link":null,"shape":7,"label":"bboxes"},{"name":"mask","type":"MASK","link":null,"shape":7,"label":"mask"},{"name":"coordinates_positive","type":"STRING","link":55,"widget":{"name":"coordinates_positive"},"shape":7,"label":"coordinates_positive"},{"name":"coordinates_negative","type":"STRING","link":61,"widget":{"name":"coordinates_negative"},"shape":7,"label":"coordinates_negative"}],"outputs":[{"name":"mask","type":"MASK","links":[59],"slot_index":0,"label":"mask"}],"properties":{"Node name for S&R":"Sam2Segmentation"},"widgets_values":[true,"","",false]},{"id":107,"type":"PreviewAnimation","pos":{"0":1340,"1":-59},"size":{"0":514.92431640625,"1":577.3973999023438},"flags":{},"order":8,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":43,"shape":7,"label":"images"},{"name":"masks","type":"MASK","link":59,"slot_index":1,"shape":7,"label":"masks"}],"outputs":[],"title":"Preview Animation 16x512x512","properties":{"Node name for S&R":"PreviewAnimation"},"widgets_values":[16,null]}],"links":[[43,102,0,107,0,"IMAGE"],[52,102,0,114,0,"IMAGE"],[53,114,0,112,0,"STRING"],[55,114,0,115,4,"STRING"],[56,106,0,115,0,"SAM2MODEL"],[57,102,0,115,1,"IMAGE"],[59,115,0,107,1,"MASK"],[60,114,1,116,0,"*"],[61,116,0,115,5,"STRING"],[62,114,1,117,0,"STRING"]],"groups":[],"config":{},"extra":{"ds":{"scale":0.5131581182307067,"offset":[396.07947776523474,760.0658700441401]}},"version":0.4}

Workflow2:

{"last_node_id":8,"last_link_id":7,"nodes":[{"id":2,"type":"SAM2ModelLoader (segment anything2)","pos":{"0":109,"1":303},"size":{"0":441,"1":58},"flags":{},"order":0,"mode":0,"inputs":[],"outputs":[{"name":"SAM2_MODEL","type":"SAM2_MODEL","links":[1],"slot_index":0,"label":"SAM2_MODEL"}],"properties":{"Node name for S&R":"SAM2ModelLoader (segment anything2)"},"widgets_values":["sam2_1_hiera_large.pt"]},{"id":3,"type":"LoadImage","pos":{"0":110,"1":427},"size":{"0":315,"1":314},"flags":{},"order":1,"mode":0,"inputs":[],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[3],"slot_index":0,"label":"IMAGE"},{"name":"MASK","type":"MASK","links":null,"label":"MASK"}],"properties":{"Node name for S&R":"LoadImage"},"widgets_values":["IMG_5539.JPG","image"]},{"id":7,"type":"MaskPreview+","pos":{"0":921,"1":433},"size":[210,246],"flags":{},"order":5,"mode":0,"inputs":[{"name":"mask","type":"MASK","link":7,"label":"mask"}],"outputs":[],"properties":{"Node name for S&R":"MaskPreview+"}},{"id":1,"type":"GroundingDinoModelLoader (segment anything2)","pos":{"0":104,"1":186},"size":{"0":554.4000244140625,"1":58},"flags":{},"order":2,"mode":0,"inputs":[],"outputs":[{"name":"GROUNDING_DINO_MODEL","type":"GROUNDING_DINO_MODEL","links":[2],"slot_index":0,"label":"GROUNDING_DINO_MODEL"}],"properties":{"Node name for S&R":"GroundingDinoModelLoader (segment anything2)"},"widgets_values":["GroundingDINO_SwinB (938MB)"]},{"id":6,"type":"PreviewImage","pos":{"0":575,"1":433},"size":[308.81640625,299.23828125],"flags":{},"order":4,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":6,"label":"images"}],"outputs":[],"properties":{"Node name for S&R":"PreviewImage"}},{"id":4,"type":"GroundingDinoSAM2Segment (segment anything2)","pos":{"0":683,"1":183},"size":{"0":554.4000244140625,"1":122},"flags":{},"order":3,"mode":0,"inputs":[{"name":"sam_model","type":"SAM2_MODEL","link":1,"label":"sam_model"},{"name":"grounding_dino_model","type":"GROUNDING_DINO_MODEL","link":2,"label":"grounding_dino_model"},{"name":"image","type":"IMAGE","link":3,"label":"image"}],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[6],"slot_index":0,"label":"IMAGE"},{"name":"MASK","type":"MASK","links":[7],"slot_index":1,"label":"MASK"}],"properties":{"Node name for S&R":"GroundingDinoSAM2Segment (segment anything2)"},"widgets_values":["person,book",0.3]}],"links":[[1,2,0,4,0,"SAM2_MODEL"],[2,1,0,4,1,"GROUNDING_DINO_MODEL"],[3,3,0,4,2,"IMAGE"],[6,4,0,6,0,"IMAGE"],[7,4,1,7,0,"MASK"]],"groups":[],"config":{},"extra":{"ds":{"scale":0.8264462809917354,"offset":[-12.505597656249961,-82.9064101562497]}},"version":0.4}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2228762.html

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

相关文章

汽车免拆诊断案例 | 2010款起亚赛拉图车发动机转速表指针不动

故障现象  一辆2010款起亚赛拉图车,搭载G4ED 发动机,累计行驶里程约为17.2万km。车主反映,车辆行驶正常,但组合仪表上的发动机转速表指针始终不动。 故障诊断  接车后进行路试,车速表、燃油存量表及发动机冷却温度…

MFC界面开发组件Xtreme Toolkit Pro v24全新发布—完整的SVG支持

Codejock软件公司的Xtreme Toolkit Pro是屡获殊荣的VC界面库,是MFC开发中最全面界面控件套包,它提供了Windows开发所需要的11种主流的Visual C MFC控件,包括Command Bars、Controls、Chart Pro、Calendar、Docking Pane、Property Grid、Repo…

基于Springboot+Vue的智慧社区数字治理平台

✌全网粉丝20W,csdn特邀作者、博客专家、CSDN新星计划导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 🍅文末获取项目下载方式🍅 一、项目背景介绍: 智慧社区作为智慧城市…

SpringMVC学习中遇到编码问题(过滤器)

一、准备 1、创建一个简单的spring项目&#xff0c;具体不多说&#xff0c;这里主要使用Java配置来搭建。 2、这里我们就只简单的添加两个主要的包&#xff08;若是想要其他的自己添加&#xff09; <dependency><groupId>org.springframework</groupId>&l…

搭建支持国密GmSSL的Nginx环境

准备 1、服务器准备&#xff1a;本文搭建使用的服务器是CentOS 7.6 2、安装包准备&#xff1a;需要GmSSL、国密Nginx&#xff0c;可通过互联网下载或者从 https://download.csdn.net/download/m0_46665077/89936158 下载国密GmSSL安装包和国密Nginx安装包。 服务器安装依赖包…

遥遥领先!手把手带你用国产香橙派部署清华AI语言模型,比肩GPT,树莓派做得到吗?

感谢 顾子韵 &#xff0c;Tass及其他朋友的帮助&#xff0c;缺少他们的帮助无法完成该教程。感兴趣的朋友私聊我或他进群一起学习。 省流中文版本 b站手把手教程&#xff0c;小伙伴们可以直接对着视频进行实践&#xff1a; 1.cd /root 来到root目录 2.apt update &&…

-XSS-

链接 https://github.com/do0dl3/xss-labs 搭建过程非常容易的 搭建好之后&#xff0c;就可以点击图片开始闯关了 第一关--JS弹窗函数alert() 显示payload的长度是4 level1.php?nametest level1.php?nametest1 发现只要改变name的值就显示什么在页面上 没有什么过滤的 …

忘记密码如何解除PPT的限制编辑?推荐两种方法!

当PPT文件设置了带密码的“只读方式”&#xff0c;文件的编辑权限就会受到限制。如果没有密码&#xff0c;就只能查看&#xff0c;而无法编辑修改PPT了。 那在忘记密码的情况下如何解除PPT的限制编辑呢&#xff1f;本文将介绍两种解除方法&#xff0c;帮助小伙伴们轻松编辑PPT…

R向量运算数组矩阵

向量的运算 向量的加减乘除可以直接进运行&#xff0c;不用循环 向量之间的运算&#xff1a;分别对应计算&#xff0c;不用循环 两个运算的向量可以不是长度相等&#xff0c;但是一定长度要成整数倍。 每种运算都可以返回逻辑值T或F 取整函数 保留小数位用round&#xff1a; …

微软官宣 GitHub Spark: 编程进入自然语言时代

今年的生活是那样悬而未决 悬置在好与烂之间&#xff0c;更偏烂一点 我没追求什么意义 我只是无所事事的来 这个世界度过了我的全部时间 我们都知道 AI 的发展可谓是一日千里&#xff0c;远超之前互联网的发展速度。在国际 AI 领域&#xff0c;微软&#xff0c;谷歌基本上已…

【成都新篇】龙信科技电子取证实验室,引领科技取证新时代

文章关键词&#xff1a;电子数据取证实验室、手机取证、介质取证、云取证、现场勘查、电子物证 在科技创新的浪潮中&#xff0c;龙信科技成都实验室以其卓越的电子数据取证服务&#xff0c;成为了中西部地区一颗璀璨的明珠。随着新址的搬迁&#xff0c;我们不仅扩大了业务范围…

.NET内网实战:通过白名单文件反序列化漏洞绕过UAC

01阅读须知 此文所节选自小报童《.NET 内网实战攻防》专栏&#xff0c;主要内容有.NET在各个内网渗透阶段与Windows系统交互的方式和技巧&#xff0c;对内网和后渗透感兴趣的朋友们可以订阅该电子报刊&#xff0c;解锁更多的报刊内容。 02基本介绍 03原理分析 在渗透测试和红…

算法日记 13 day 二叉树

今天继续二叉树啊&#xff01;&#xff01;&#xff01; 题目&#xff1a;平衡二叉树 110. 平衡二叉树 - 力扣&#xff08;LeetCode&#xff09; 给定一个二叉树&#xff0c;判断它是否是 平衡二叉树 题目分析&#xff1a; 平衡二叉树指的是一个二叉树每个节点 的左右两个子树…

「C/C++」C/C++ 之 动态内存分配

✨博客主页何曾参静谧的博客&#x1f4cc;文章专栏「C/C」C/C程序设计&#x1f4da;全部专栏「VS」Visual Studio「C/C」C/C程序设计「UG/NX」BlockUI集合「Win」Windows程序设计「DSA」数据结构与算法「UG/NX」NX二次开发「QT」QT5程序设计「File」数据文件格式「PK」Parasoli…

人工智能_神经网络103_感知机_感知机工作原理_感知机具备学习能力_在学习过程中自我调整权重_优化效果_多元线性回归_逻辑回归---人工智能工作笔记0228

由于之前一直对神经网络不是特别清楚,尤其是对神经网络中的一些具体的概念,包括循环,神经网络卷积神经网络以及他们具体的作用,都是应用于什么方向不是特别清楚,所以现在我们来做教程来具体明确一下。 当然在机器学习之后还有深度学习,然后在深度学习中对各种神经网络的…

idea使用Translation插件实现翻译

1.打开idea&#xff0c;settings&#xff0c;选择plugins&#xff0c;搜索插件Translation&#xff0c;安装 2.选择翻译引擎 3.配置引擎&#xff0c;以有道词典为例 3.1 获取应用ID&#xff0c;应用秘钥 3.1.1 创建应用 点击进入有道智云控制台 3.1.2 复制ID和秘钥 3.2 idea设…

Mac下载 安装MIMIC-IV 3.0数据集

参考blog MIMIC IV 3.0数据库安装方法_mimic数据下载-CSDN博客 MIMIC IV数据库安装&#xff08;二&#xff09;_mimic数据库安装-CSDN博客 MIMIC-IV3.0安装_mimic iv 3.0-CSDN博客 MIMIC-IV-v2.0安装教程_mimic iv 安装教程-CSDN博客 MIMIC IV 3.0数据库安装方法或者思路&…

力扣——另一个的子树(C语言)

1.题目&#xff1a; 给你两棵二叉树 root 和 subRoot 。检验 root 中是否包含和 subRoot 具有相同结构和节点值的子树。如果存在&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。二叉树 tree 的一棵子树包括 tree 的某个节点和这个节点的所有后代节点。tree …

为什么说Tcp是面向字节流的以及(Tcp粘包问题、TCP/UDP对比、listen函数的backlog参数的意义)

为什么说Tcp是面向字节流的&#xff1a; Tcp通信的本质是创建一个tcp的socket&#xff0c;同时就会对应的创建一个发送缓冲区和接收缓冲区。 调用write时, 数据会先写入发送缓冲区中;如果发送的字节数太长, 会被拆分成多个TCP的数据包发出如果发送的字节数太短, 就会先在缓冲…

92.【C语言】数据结构之单向链表的查找,中间插入和删除,销毁

目录 1.链表的查找函数 2.链表的修改函数 3.链表的中间插入函数 1.在pos之前插入:SLTInsertBefore函数 1.借助头指针pphead 示意图 代码示例(写入SList.c) 头文件添加SLTInsertbefore的声明 main.c的部分代码改为 1.测试中间插入 2.测试头部插入 3.测试pos为NULL的…