ImageSegmentationCustomAdvanced
When your ONNX model won't cut out right, this is the fix
- images
- IMAGE
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 sharedmeanand one sharedstd; 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.onnxfiles inmodels/onnx.mean_r/mean_g/mean_b(defaults 0.485/0.456/0.406) andstd_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.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| model | COMBO | 0 options: | |
| alpha_matting | COMBO | 2 options: true, false | |
| alpha_matting_foreground_threshold | INT | 240 | — |
| alpha_matting_background_threshold | INT | 20 | — |
| alpha_matting_erode_size | INT | 10 | — |
| post_process_mask | COMBO | 2 options: false, true | |
| mean_r | FLOAT | 0.48 | — |
| mean_g | FLOAT | 0.46 | — |
| mean_b | FLOAT | 0.41 | — |
| std_r | FLOAT | 1.00 | — |
| std_g | FLOAT | 1.00 | — |
| std_b | FLOAT | 1.00 | — |
| width | INT | 1024 | — |
| height | INT | 1024 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |