Comfy-Org/ComfyUI · error · ValueError

SeedVR2PostProcessing: expected 4-D or 5-D IMAGE tensor, got

Error message

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

What it means

SeedVR2PostProcessing._as_bthwc normalizes the decoded/reference IMAGE inputs to a 5-D (B,T,H,W,C) batch. A 4-D input is treated as a single video (batch added); a 5-D input passes through; any other rank raises this error with the offending shape.

Source

Thrown at comfy_extras/nodes_seedvr.py:232

        if alpha_input is not None:
            alpha_5d, _ = cls._as_bthwc(alpha_input)
            alpha_5d = alpha_5d[:output.shape[0], :output.shape[1], :output.shape[2], :output.shape[3], :]
            output = torch.cat([output, alpha_5d.to(dtype=output.dtype, device=output.device)], dim=-1)
        h2 = output.shape[-3] - (output.shape[-3] % 2)
        w2 = output.shape[-2] - (output.shape[-2] % 2)
        output = output[:, :, :h2, :w2, :]
        if decoded_was_4d:
            output = output.reshape(-1, output.shape[-3], output.shape[-2], output.shape[-1])
        return io.NodeOutput(output)

    @staticmethod
    def _as_bthwc(images):
        if images.ndim == 4:
            return images.unsqueeze(0), True
        if images.ndim == 5:
            return images, False
        raise ValueError(
            f"SeedVR2PostProcessing: expected 4-D or 5-D IMAGE tensor, got shape {tuple(images.shape)}"
        )

    @staticmethod
    def _restore_reference_batch_time(decoded, reference):
        if decoded.shape[0] != 1:
            return decoded
        ref_b, ref_t = reference.shape[:2]
        if ref_b < 1 or decoded.shape[1] % ref_b != 0:
            return decoded
        decoded_t = decoded.shape[1] // ref_b
        if decoded_t < ref_t:
            return decoded
        return decoded.reshape(ref_b, decoded_t, decoded.shape[2], decoded.shape[3], decoded.shape[4])

    @staticmethod
    def _to_seedvr2_raw(images):
        return images.mul(2.0).sub(1.0)

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Feed only Comfy IMAGE tensors of shape (N,H,W,C) or (B,N,H,W,C) into the node's image/reference inputs.
  2. Verify with print(t.ndim, t.shape) at the source; unsqueeze(0) adds the missing batch dim for 3-D data.
  3. Check for accidental double batching (two unsqueeze(0) calls) in custom preprocessing.

Example fix

# before
ref = ref[0]           # (H, W, C) 3-D -> error

# after
ref = ref[0].unsqueeze(0)  # (1, H, W, C) 4-D accepted
Defensive patterns

Strategy: type-guard

Validate before calling

def as_bthwc(t):
    if t.dim() == 4:
        return t.unsqueeze(0)
    if t.dim() == 5:
        return t
    raise ValueError(f'expected 4-D/5-D IMAGE, got {tuple(t.shape)}')

Type guard

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

Prevention

When it happens

Trigger: Connecting a 3-D or 6-D tensor to SeedVR2PostProcessing's image or reference input, e.g. a latent in NCHW, or a doubly-batched tensor from a custom node.

Common situations: Wrong-type wire connections (LATENT/MASK into IMAGE); custom nodes that squeeze or stack extra dims; scripts constructing tensors manually with wrong rank.

Related errors


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