{"record":{"id":"3b5f400a5aa47e18","repo":"Comfy-Org/ComfyUI","slug":"seedvr2postprocessing-expected-4-d-or-5-d-image-t","errorCode":null,"errorMessage":"SeedVR2PostProcessing: expected 4-D or 5-D IMAGE tensor, got shape {tuple(images.shape)}","messagePattern":"SeedVR2PostProcessing: expected 4-D or 5-D IMAGE tensor, got shape (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_seedvr.py","lineNumber":232,"sourceCode":"\n        if alpha_input is not None:\n            alpha_5d, _ = cls._as_bthwc(alpha_input)\n            alpha_5d = alpha_5d[:output.shape[0], :output.shape[1], :output.shape[2], :output.shape[3], :]\n            output = torch.cat([output, alpha_5d.to(dtype=output.dtype, device=output.device)], dim=-1)\n        h2 = output.shape[-3] - (output.shape[-3] % 2)\n        w2 = output.shape[-2] - (output.shape[-2] % 2)\n        output = output[:, :, :h2, :w2, :]\n        if decoded_was_4d:\n            output = output.reshape(-1, output.shape[-3], output.shape[-2], output.shape[-1])\n        return io.NodeOutput(output)\n\n    @staticmethod\n    def _as_bthwc(images):\n        if images.ndim == 4:\n            return images.unsqueeze(0), True\n        if images.ndim == 5:\n            return images, False\n        raise ValueError(\n            f\"SeedVR2PostProcessing: expected 4-D or 5-D IMAGE tensor, got shape {tuple(images.shape)}\"\n        )\n\n    @staticmethod\n    def _restore_reference_batch_time(decoded, reference):\n        if decoded.shape[0] != 1:\n            return decoded\n        ref_b, ref_t = reference.shape[:2]\n        if ref_b < 1 or decoded.shape[1] % ref_b != 0:\n            return decoded\n        decoded_t = decoded.shape[1] // ref_b\n        if decoded_t < ref_t:\n            return decoded\n        return decoded.reshape(ref_b, decoded_t, decoded.shape[2], decoded.shape[3], decoded.shape[4])\n\n    @staticmethod\n    def _to_seedvr2_raw(images):\n        return images.mul(2.0).sub(1.0)","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_seedvr.py#L214-L250","documentation":"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.","triggerScenarios":"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.","commonSituations":"Wrong-type wire connections (LATENT/MASK into IMAGE); custom nodes that squeeze or stack extra dims; scripts constructing tensors manually with wrong rank.","solutions":["Feed only Comfy IMAGE tensors of shape (N,H,W,C) or (B,N,H,W,C) into the node's image/reference inputs.","Verify with print(t.ndim, t.shape) at the source; unsqueeze(0) adds the missing batch dim for 3-D data.","Check for accidental double batching (two unsqueeze(0) calls) in custom preprocessing."],"exampleFix":"# before\nref = ref[0]           # (H, W, C) 3-D -> error\n\n# after\nref = ref[0].unsqueeze(0)  # (1, H, W, C) 4-D accepted","handlingStrategy":"type-guard","validationCode":"def as_bthwc(t):\n    if t.dim() == 4:\n        return t.unsqueeze(0)\n    if t.dim() == 5:\n        return t\n    raise ValueError(f'expected 4-D/5-D IMAGE, got {tuple(t.shape)}')","typeGuard":"def is_image_4d_or_5d(t) -> bool:\n    return t.dim() in (4, 5)","tryCatchPattern":null,"preventionTips":["Connect only IMAGE-type wires to postprocessing image/reference inputs.","Avoid double unsqueeze in custom batching code.","Print tensor rank at each custom-node boundary while debugging."],"tags":["seedvr","tensor-shape","validation","postprocessing"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}