ZML_YOLO到遮罩
Turn YOLO detections into real masks, strokes, and cutouts — ZML_YOLO到遮罩
- 图像
- 遮罩
- 反转遮罩
- 描边图像
- 裁剪图像
ZML_YOLO到遮罩 is the pack's bridge between a YOLO object detector and the mask-based tools of ComfyUI. Feed it an image, and it runs a YOLO model, merges every detected instance into a single mask, and hands you the mask, its inverse, an outline-drawn preview, and a cut-out of the subject. It's the "make me a mask of the person/face/hands automatically" node - the detection half of an auto-detailer loop, minus the re-render.
Here's what actually happens, because the four outputs each do one job:
遮罩- combined mask of every detection, scaled and dilated to taste反转遮罩- its inverse (everything except the subject - wire this into a background-inpaint)描边图像- your original image with contour outlines drawn on it (color from描边颜色, thickness from描边厚度). Great for sanity-checking what the model found.裁剪图像- the detected subject cut out onto transparency; with保持裁剪图像原始分辨率off, it auto-trims to the tight bounding box (a 1×1 transparent placeholder if nothing was found)
Tuning controls are where the quality lives. 置信度阈值 (0–1, default 0.5) filters weak detections. 遮罩缩放系数 (0.1–5) and 遮罩膨胀 (0–128px) let you shrink or inflate the mask - inflate a face mask a few pixels before inpainting and you stop the seam, exactly the trick the KB's masking doc describes. The YOLO模型 dropdown lists models from ComfyUI's models/ultralytics folder - the standard face_yolov8n/s, hand_yolov8n/s, person_yolov8n-seg files people already have from ADetailer-style work. It's the same detector ecosystem the KB calls "swappable input, not a fixed part": drop any .pt in the folder and it appears.
Installing it
Ships in ComfyUI-ZML-Image, but this one has a real extra dependency: the ultralytics Python package. Manager installs the pack's requirements.txt (which lists ultralytics, opencv-python, plus the usual torch/Pillow). If you install manually:
cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image
cd ComfyUI
pip install ultralytics opencv-python
And you need a YOLO model: drop face_yolov8n.pt or similar into ComfyUI/models/ultralytics/. The README's history shows a recurring fix for "YOLO model not being read" - check the models folder first if the dropdown is empty.
Common issues
The dropdown being empty is the #1 problem, and it's environmental: YOLO模型 reads from models/ultralytics, so a model sitting in models/checkpoints won't show up. Put the file in the right folder and refresh.
Beyond that, manage expectations on what a bbox detector gives you. The KB's detailing doc is blunt: a bbox model produces rectangular masks that hug a face roughly, while a segmentation model (-seg suffix) produces polygon masks that follow the outline - much cleaner for inpainting. If your mask looks like a box around the subject, that's the model, not the node; swap to a -seg variant. And the auto-crop on 裁剪图像 can surprise: with 保持裁剪图像原始分辨率 off, an empty detection returns a 1×1 transparent image, which downstream nodes may choke on. If that happens, keep the resolution toggle on.
One more: the node inherits its YOLO loading from the pack's auto-censor machinery, and loads the model in a "compatibility mode" wrapper - if you see a version warning from ultralytics on import, it's cosmetic. This is the well-tested half of the pack (auto-censor has been around since early updates), so the mask math is solid; the failures are almost all model-folder and model-choice problems.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| 图像 | IMAGE | — | |
| YOLO模型 | COMBO | 0 options: | |
| 置信度阈值 | FLOAT | 0.500–1 | — |
| 遮罩缩放系数 | FLOAT | 1.000.1–5 | — |
| 遮罩膨胀 | INT | 00–128 | — |
| 描边颜色 | STRING | #FF0000 | 描边颜色,十六进制代码 (例如 #RRGGBB)。默认红色。 |
| 描边厚度 | INT | 20–30 | — |
| 保持裁剪图像原始分辨率 | BOOLEAN | false | 如果为True,裁剪图像将保持原始输入图像的分辨率并填充透明像素;如果为False,裁剪图像将自动剪裁周围的透明区域,只保留最小有效内容。 |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| 遮罩 | MASK | — |
| 反转遮罩 | MASK | — |
| 描边图像 | IMAGE | — |
| 裁剪图像 | IMAGE | — |