Jags-YoloSegNode
Mask every person, nothing else
- image
- SEG_IMAGE
- SEG_MASK
This is the node that actually gives you a mask. Jags-YoloSegNode runs an Ultralytics YOLOv8 segmentation model on your image, filters the detections down to the class you pick, and returns a binary mask of every instance of that class - plus the annotated image showing what was found.
Concrete example: you've got a photo of a crowd and you want every person masked so you can edit them separately. class_id defaults to 0, which in the COCO class list is "person." One run, and the SEG_MASK output covers all of them. Try doing that by hand-painting, then come back and thank it.
How it works
The node loads a YOLO seg model, runs inference, and reads both the masks and the detection boxes from the results. Each box carries a class id, so it filters the masks to instances whose class matches your class_id, then ORs those instance masks together into a single binary mask (values 0/255) and returns it. The annotated image shows everything the model detected, not just your chosen class - the filter only applies to the mask output.
One important consequence: with class_id set to something the image doesn't contain, the mask comes back empty while the annotated image still shows whatever else was found. That's the filter doing its job, not a bug.
Inputs
- image (required,
IMAGE) - single image, same as the sibling detection node (it squeezes the batch). - model_name (required) - dropdown populated from
ComfyUI/models/yolov8/. Empty until you drop model files in there. - class_id (required,
INT, default 0) - which COCO class to keep. 0 = person. Check your model's class list (printed to console on load, or from the Ultralytics docs) for vehicles, animals, and the rest.
Outputs:
- SEG_IMAGE (
IMAGE) - the annotated image with all detections drawn. - SEG_MASK (
MASK) - the binary mask of your chosen class. Wire this intoSet Latent Noise Maskfor inpainting, or into any masking/compositing step.
The model requirement - the #1 gotcha
This node needs a -seg model. yolov8m-seg.pt, yolov8s-seg.pt, and up - the README links to the Ultralytics segmentation models page, and the author's HuggingFace collection bundles seg weights plus face-detection models.
A plain detection model like yolov8m.pt will not work: the code reads results[0].masks, which is None for detect-only weights. You'll get an error or an empty mask, and it's the most common reason this node "doesn't work" for people. If in doubt, the filename says it - you need the -seg suffix.
mkdir -p ComfyUI/models/yolov8
# drop yolov8m-seg.pt in there, restart ComfyUI
Same casing note as the rest of the pack: the code reads lowercase models/yolov8, even though the README capitalizes it. Windows shrugs; Linux cares.
Installing
ComfyUI Manager → search Jags_VectorMagic → install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/jags111/ComfyUI_Jags_VectorMagic
ultralytics comes via the pack's requirements, so the YOLO runtime is handled. The rest of the requirements list (librosa, clip-interrogator, opencv-python, …) installs whether you need it or not.
Where it fits
Person/vehicle/animal masks feeding into inpainting, background separation, or region-limited edits are the obvious use. It's less precise at edges than a dedicated segmentation model like SAM or BiRefNet - YOLO masks follow the box-level outline, not hair strands - so for fine-edged cutouts you'd still reach for a real matting model. But when the job is "all instances of one class, fast, no training," this is a one-node solution that just works.
One more tip: it reloads the model from disk on every execution. Loop it and you'll wait; keep it out of heavy iteration.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| model_name | COMBO | 0 options: | |
| class_id | INT | 0 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| SEG_IMAGE | IMAGE | — |
| SEG_MASK | MASK | — |