Nodes/ComfyUI FSL Nodes/FSL / Ensure NHWC Batch
ComfyUI Node

FSL / Ensure NHWC Batch

FSL / Ensure NHWC Batch — make every image tensor agree on shape

By fredlef·Created about a year ago·Updated 9 months ago· 13
FSL / Ensure NHWC Batch
  • image
  • image_nhwc

Every ComfyUI user eventually hits the shape war. Some custom nodes emit [N, H, W, C] (NHWC) image tensors, some emit [N, C, H, W] (NCHW), some hand you rank-3 tensors that are HWC, CHW, or even HCW, and downstream nodes quietly explode or produce garbage when the convention doesn't match. FSL Ensure NHWC Batch is the FSL pack's peace treaty: it takes any image tensor and guarantees the output is [N, H, W, C] float32, clamped to [0,1]. The README's framing is exactly that - it "guarantees incoming image tensors are converted to [N, H, W, C] layout, ensuring compatibility across different node packs."

How it works

The node inspects the tensor's rank and channel position and permutes accordingly:

  • Rank 3 (H,W,C / C,H,W / H,C,W) - it detects which axis holds 3 or 4 channels and transposes to HWC, then adds a batch dimension → 1,H,W,C.
  • Rank 4 (N,H,W,C / N,C,H,W / N,H,C,W) - same detection at the batch level, permuting to NHWC but keeping N.
  • Anything else - it raises a clear ValueError instead of guessing.

It also forces float32 and clamps to [0,1]. Two deliberate behaviors to note:

  • Alpha gets dropped. If the result has 4 channels, the node trims to RGB. The code comment says it's so "esrgan-like models stay happy" - a flat RGB NHWC batch is the safest common denominator.
  • It takes one image, not a list. The input is a single IMAGE; a list input just gets its first element processed. Feed it one tensor at a time and you'll be fine.

The input/output

  • image (required) - any IMAGE tensor. This is the only input.
  • image_nhwc - the normalized [N,H,W,C] float32 tensor, alpha stripped.

Where it fits

This is a compatibility shim, and its natural home is at the boundary between node packs: right after a node you don't control, before one that's picky. If you're chaining FSL's Gemini outputs into an upscaler or a compositor that's temperamental about layout, drop this in between and remove one whole class of "shape mismatch" errors from your debugging. It's also handy as a normalization point if you're feeding a mix of sources into one downstream consumer.

Install & the honest note

It ships with the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/fredlef/Comfyui_FSL_Nodes
cd Comfyui_FSL_Nodes
pip install -r requirements.txt

or ComfyUI Manager → "ComfyUI FSL Nodes", then restart. Local-only, no API key, costs nothing.

The honest note: in stock ComfyUI, most nodes already agree on NHWC, so this node is a "belt and suspenders" utility rather than a daily driver. You'll reach for it the moment you import an exotic custom node that breaks the convention - and then you'll be glad it exists. Just remember it strips alpha, so if you're passing an RGBA image you actually want to keep transparent, don't route it through here.

CategoryFSL Nodes

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
image_nhwcIMAGE