Nodes/Allor Plugin/ImageSegmentationCustomAdvanced
ComfyUI Node

ImageSegmentationCustomAdvanced

When your ONNX model won't cut out right, this is the fix

By Nourepide·Created 3 years ago·Updated 2 years ago· 295
ImageSegmentationCustomAdvanced
  • images
  • IMAGE
model
alpha_matting
alpha_matting_foreground_threshold240
alpha_matting_background_threshold20
alpha_matting_erode_size10
post_process_mask
mean_r0.48
mean_g0.46
mean_b0.41
std_r1.00
std_g1.00
std_b1.00
width1024
height1024

You converted a segmentation model to ONNX, dropped it in models/onnx, ran ImageSegmentationCustom... and got noise instead of a mask. Nine times out of ten the problem is normalization or input resolution: the model was trained with specific per-channel means/stds and a specific aspect ratio, and the simple node fed it generic values. ImageSegmentationCustomAdvanced exists to fix exactly that. It's the same rembg-backed custom ONNX cutout, but it splits every pretrained-model assumption into its own dial - separate mean_r/g/b, std_r/g/b, and independent width/height - so you can match whatever the checkpoint actually expects.

How it works

Mechanically it's identical to ImageSegmentationCustom: Allor registers an onnx folder type, points rembg's U2NET_HOME at ComfyUI/models/onnx, and the model dropdown lists the .onnx files there. The node wraps your model in a custom rembg session that normalizes the input with the means/stds you set, resizes to the width/height you set, runs it through onnxruntime, and rescales the predicted mask back to full resolution. Then the mask flows through rembg's remove() pipeline with the same alpha-matting and post-process controls.

The difference is entirely in the granularity of the prep:

  • Per-channel means/stds. Many segmentation checkpoints - especially portrait matting and newer backbones - normalize with distinct values per color channel (think ImageNet-style 0.485/0.456/0.406). The plain Custom node forces one shared mean and one shared std; this node lets you match each channel exactly. Wrong means produce garbage, and this is how you fix it without re-exporting the model.
  • Independent width and height. Some ONNX exports expect a fixed non-square input (e.g. 512×768), while the plain node only gives you a single square size. Here you can feed the model's native resolution, which is also the fix for aspect-ratio distortion in the mask.

The quality knobs carry over unchanged: alpha_matting (true/false) toggles the pymatting refinement pass for hair and soft edges, tuned by alpha_matting_foreground_threshold (default 240), alpha_matting_background_threshold (default 20), and alpha_matting_erode_size (default 10); post_process_mask (true/false) applies final cleanup. Output is RGBA IMAGE with the background transparent - the pack preserves alpha, so it composites cleanly.

Inputs and outputs

  • images (IMAGE) - single frame or batch.
  • model - dropdown of .onnx files in models/onnx.
  • mean_r/mean_g/mean_b (defaults 0.485/0.456/0.406) and std_r/std_g/std_b (defaults 1.0) - per-channel normalization.
  • width (default 1024), height (default 1024), both stepped by 8 - inference input size.
  • alpha_matting, thresholds, erode_size, post_process_mask - rembg refinement.

Output: IMAGE, RGBA.

Installing it and the model bit

Same pack, same install: ComfyUI Manager → "Allor Plugin", or clone https://github.com/Nourepide/ComfyUI-Allor into custom_nodes and restart. Put your model at ComfyUI/models/onnx/your-model.onnx and reload so the dropdown sees it. The rembg and onnx dependencies install with the pack; onnxruntime GPU is optional and worth it for batches.

Where people get burned

This node is a precision instrument, which means its failure mode is the opposite of the simple one: too many knobs, and you tune the wrong thing. The order that works: first set width/height to the model's native input, then the means/stds from the model's export notes or its training code, and only touch the alpha-matting thresholds when the edges themselves are bad. If you don't know a model's normalization values, the honest move is to check the repo it came from - guessing per-channel means and hoping is how people end up blaming the node for a checkpoint mismatch. And as always, alpha_matting is a CPU-heavy pass; leave it off until the coarse mask is already right.

Categoryimage/segmentation

Inputs (15)

NameTypeDefaultDescription
imagesIMAGE
modelCOMBO0 options:
alpha_mattingCOMBO2 options: true, false
alpha_matting_foreground_thresholdINT240
alpha_matting_background_thresholdINT20
alpha_matting_erode_sizeINT10
post_process_maskCOMBO2 options: false, true
mean_rFLOAT0.48
mean_gFLOAT0.46
mean_bFLOAT0.41
std_rFLOAT1.00
std_gFLOAT1.00
std_bFLOAT1.00
widthINT1024
heightINT1024

Outputs (1)

NameTypeDescription
IMAGEIMAGE