Comfy-Org/ComfyUI · error · ValueError

{node_name}: expected 4-D or 5-D IMAGE tensor, got shape {tu

Error message

{node_name}: expected 4-D or 5-D IMAGE tensor, got shape {tuple(images.shape)}

What it means

_seedvr2_input_shorter_edge computes the shorter spatial edge of an IMAGE tensor to derive upscale targets. It only accepts 4-D (N,H,W,C) or 5-D (B,N,H,W,C) Comfy IMAGE layouts; any other rank fails immediately with this message echoing the offending shape.

Source

Thrown at comfy_extras/nodes_seedvr.py:97

    if t == 1:
        return videos
    if t <= 4:
        padding = videos[:, -1:].repeat(1, 4 - t + 1, 1, 1, 1)
        return torch.cat([videos, padding], dim=1)
    if (t - 1) % 4 == 0:
        return videos
    padding = videos[:, -1:].repeat(1, 4 - ((t - 1) % 4), 1, 1, 1)
    videos = torch.cat([videos, padding], dim=1)
    if (videos.size(1) - 1) % 4 != 0:
        raise ValueError(f"SeedVR2Preprocess failed to pad video length to 4n+1; got {videos.size(1)} frames.")
    return videos

def _seedvr2_input_shorter_edge(images, node_name):
    if images.dim() == 4:
        return min(images.shape[1], images.shape[2])
    if images.dim() == 5:
        return min(images.shape[2], images.shape[3])
    raise ValueError(
        f"{node_name}: expected 4-D or 5-D IMAGE tensor, "
        f"got shape {tuple(images.shape)}"
    )


def _seedvr2_pad(images, upscaled_shorter_edge, node_name):
    if upscaled_shorter_edge < 2:
        raise ValueError(
            f"{node_name}: input shorter edge must be at least 2 pixels; "
            f"got {upscaled_shorter_edge}."
        )
    if images.shape[-1] > 3:
        images = images[..., :3]
    if images.dim() == 4:
        # Comfy video components arrive as a 4-D IMAGE frame sequence:
        # (frames, H, W, C). SeedVR2 consumes that as one video.
        images = images.unsqueeze(0)
    elif images.dim() != 5:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Ensure the input has shape (N,H,W,C) or (B,N,H,W,C); add a batch dimension with .unsqueeze(0) if you have a bare (H,W,C) image.
  2. Check the wiring: connect a LoadImage/LoadVideo IMAGE output, not a LATENT or MASK.
  3. In custom code, print images.dim() and images.shape right before the node call to confirm rank.

Example fix

# before
img = img.squeeze(0)  # now (H, W, C), 3-D -> error
out = seedvr_node(img)

# after
if img.dim() == 3:
    img = img.unsqueeze(0)  # (1, H, W, C)
out = seedvr_node(img)
Defensive patterns

Strategy: type-guard

Validate before calling

def to_comfy_image(t):
    if t.dim() == 3:
        t = t.unsqueeze(0)
    assert t.dim() in (4, 5), f'expected 4-D/5-D IMAGE, got {tuple(t.shape)}'
    return t

Type guard

def is_comfy_image(t) -> bool:
    return t.dim() in (4, 5)

Prevention

When it happens

Trigger: Calling a SeedVR2 upscale node with a tensor that is not 4-D or 5-D — e.g. a raw 3-D (H,W,C) single image without a batch dim, or a 6-D tensor from a custom node that nests batches.

Common situations: Custom nodes that squeeze the batch dimension; passing a latent (4-D NCHW) where an IMAGE was expected; manually constructing an image tensor with the wrong rank in a script.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/824113bfb0c010ea. Report an issue: GitHub.