ComfyUI-SAMURAI–SAM2-

ComfyUI-SAMURAI–SAM2-
★ 44

视频分割SAMURAIComfyUI节点掩码生成
基于SAMURAI(SAM2)模型的ComfyUI节点,用于对视频帧进行目标分割并生成高质量掩码,方便在流程中进行后续编辑与跟踪。
💡 在ComfyUI中对视频帧进行目标分割并输出可编辑掩码。
🍴 5 Forks💻 Python🔄 2024-12-01
📦
网盘下载
复制链接后前往夸克网盘下载
https://pan.quark.cn/s/a9fb3a59e10c
📦 requirements.txt
loguru
hydra-core
omegaconf
torch>=2.0.0
torchvision>=0.15.0
numpy>=1.20.0
pillow>=8.0.0
opencv-python>=4.5.0
📄 README

SAMURAI Nodes for ComfyUI

ComfyUI nodes for video object segmentation using SAMURAI model.

Installation

Note: It is recommended to use Conda environment for installation and running the nodes.

Make sure to use the same Conda environment for both ComfyUI and SAMURAI installation!

It is highly recommended to use the console version of ComfyUI

## Requirements

  • NVIDIA GPU with CUDA support
  • Python 3.10 or higher
  • ComfyUI
  • Conda (recommended) or pip
  • Follow the SAMURAI installation guide to install the base model
  • Clone this repository into your ComfyUI custom nodes directory:
  • cd ComfyUI/custom_nodes
    
    
    
    git clone https://github.com/takemetosiberia/ComfyUI-SAMURAI--SAM2-.git samurai_nodes
    

  • Copy the SAMURAI installation folder into ComfyUI/custom_nodes/samurai_nodes/
  • Download model weights as described in SAMURAI guide
  • Project Structure

    After installation, your directory structure should look like this:

    ComfyUI/
    
    └── custom_nodes/
    
        └── samurai_nodes/
    
            ├── samurai/     # SAMURAI model installation
    
            ├── init.py      # Module initialization
    
            ├── samurai_node.py
    
            └── utils.py
    

    Additional Dependencies

    Most dependencies are included with SAMURAI installation. Additional required packages:

    pip install hydra-core omegaconf loguru
    

    Usage

    The workflow consists of three main nodes:

    SAMURAI Box Input

    Allows selecting a region of interest (box) in the first frame of a video sequence.

  • Input: video frames
  • Output: box coordinates and start frame number
  • SAMURAI Points Input

    Enables point-based object selection in the first frame.

  • Input: video frames
  • Output: point coordinates, labels, and start frame number
  • SAMURAI Refine

    Performs video object segmentation using selected area.

  • Input: video frames, box/points from input nodes
  • Output: segmentation masks
  • Example Workflow

  • Connect Load Video to SAMURAI Box/Points Input
  • Draw box or place points around object of interest
  • Connect to SAMURAI Refine
  • Convert masks to images and save/combine as needed
  • For more examples and details, see SAMURAI documentation.

    Troubleshooting

    If you encounter any issues:

  • Make sure you’re using the correct Conda environment
  • Verify that all dependencies are installed in your Conda environment
  • Check if SAMURAI models is properly installed in the samurai/sam2/checkpoints directory
  • For CUDA-related issues, ensure your Conda environment has the correct PyTorch version with CUDA support.