← See All Custom Node Packs

ComfyUI-segment-anything-2

1206

Run ComfyUI Easily with InstaSD

Skip the complex setup and run ComfyUI online. InstaSD helps creative professionals build workflows and deploy them to the world:

  • One-click deployment
  • Any model, any node
  • Powerful GPUs for rapid iteration
Get Started

Sam2VideoSegmentationAddPoints

Sam2VideoSegmentationAddPoints Node Documentation

Introduction

The Sam2VideoSegmentationAddPoints node is part of the ComfyUI segment anything implementation for video segmentation using the SAM2 model. This node is specifically used to add point-based annotations to a video frame for object segmentation. It works by providing the SAM2 model with positive and optional negative point coordinates that are used to guide the segmentation process. The node facilitates adding these points at precise frames and object indices, enabling fine-grained control over the segmentation task.

Node Functionality

The Sam2VideoSegmentationAddPoints node allows users to:

  1. Annotate specific frames in a video with positive and negative points for segmentation.
  2. Control which object and frame the points should be applied to by specifying object and frame indices.
  3. Use previous inference states to continue the segmentation process without reinitializing the inference state.

Inputs

Here are the inputs that the Sam2VideoSegmentationAddPoints node accepts:

  • sam2_model: The SAM2 model intended for video segmentation use. This model needs to be loaded beforehand using an appropriate model loading node.

  • coordinates_positive: A JSON-formatted string representing the positive point coordinates. These points indicate the locations where the object to be segmented is present.

  • frame_index: An integer specifying the frame in the video where the points should be added.

  • object_index: An integer specifying the object ID to which the points belong. This is useful when dealing with multiple objects in a single frame.

Optional Inputs

  • image: The image (or video frame) to initialize the inference state. This is only needed if a previous inference state is not provided.

  • coordinates_negative: A JSON-formatted string representing the negative point coordinates. These points indicate regions where the object is not present and help refine the segmentation.

  • prev_inference_state: A previously saved inference state. If provided, it is used to continue the segmentation process from that state, optimizing computational resources.

Outputs

The node produces the following outputs:

  • sam2_model: The updated SAM2 model including the new point annotations for video segmentation. This allows further segmentation steps or processes to use the updated model.

  • inference_state: The state of the model's inference after adding the points. This state can be used in subsequent frames to maintain continuity and accuracy in segmentation.

Usage in ComfyUI Workflows

The Sam2VideoSegmentationAddPoints node is typically used in a segmentation workflow where:

  1. A video is being segmented frame by frame, and precise control over annotations is needed.
  2. Users want to leverage previously calculated inference states to improve segmentation efficiency.
  3. Annotation points (including positive and negative) are crucial for identifying and refining the boundaries of objects within video frames.

A common workflow might involve:

  • Loading a video and initializing the SAM2 model.
  • For each frame where segmentation is needed, using the Sam2VideoSegmentationAddPoints node to add annotations.
  • Employing other nodes to complete the segmentation and analyze or visualize the outputs.

Special Features or Considerations

  • Precision in Segmentation: By using point annotations, users can significantly improve the precision of segmentations by correcting areas where the model might be uncertain.
  • Efficiency with Inference States: The option to use a previous inference state allows for efficient handling of video segmentation tasks, as it negates the need for reprocessing frames from scratch.
  • JSON Input for Coordinates: Point coordinates need to be supplied in JSON format, which might require users to format their input data accordingly.
  • Compatibility: Ensure that the SAM2 model loaded is suitable for video segmentation as the node is specifically designed for this purpose.

This node is a convenient tool in the segmentation toolbox of ComfyUI, providing users the capability to undertake complex video segmentation tasks with guided annotations.

Want to try ComfyUI-segment-anything-2 without installing anything? Run ComfyUI online on InstaSD's cloud GPUs — no setup required.