{"record":{"id":"824113bfb0c010ea","repo":"Comfy-Org/ComfyUI","slug":"node-name-expected-4-d-or-5-d-image-tensor-got","errorCode":null,"errorMessage":"{node_name}: expected 4-D or 5-D IMAGE tensor, got shape {tuple(images.shape)}","messagePattern":"(.+?): 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":97,"sourceCode":"    if t == 1:\n        return videos\n    if t <= 4:\n        padding = videos[:, -1:].repeat(1, 4 - t + 1, 1, 1, 1)\n        return torch.cat([videos, padding], dim=1)\n    if (t - 1) % 4 == 0:\n        return videos\n    padding = videos[:, -1:].repeat(1, 4 - ((t - 1) % 4), 1, 1, 1)\n    videos = torch.cat([videos, padding], dim=1)\n    if (videos.size(1) - 1) % 4 != 0:\n        raise ValueError(f\"SeedVR2Preprocess failed to pad video length to 4n+1; got {videos.size(1)} frames.\")\n    return videos\n\ndef _seedvr2_input_shorter_edge(images, node_name):\n    if images.dim() == 4:\n        return min(images.shape[1], images.shape[2])\n    if images.dim() == 5:\n        return min(images.shape[2], images.shape[3])\n    raise ValueError(\n        f\"{node_name}: expected 4-D or 5-D IMAGE tensor, \"\n        f\"got shape {tuple(images.shape)}\"\n    )\n\n\ndef _seedvr2_pad(images, upscaled_shorter_edge, node_name):\n    if upscaled_shorter_edge < 2:\n        raise ValueError(\n            f\"{node_name}: input shorter edge must be at least 2 pixels; \"\n            f\"got {upscaled_shorter_edge}.\"\n        )\n    if images.shape[-1] > 3:\n        images = images[..., :3]\n    if images.dim() == 4:\n        # Comfy video components arrive as a 4-D IMAGE frame sequence:\n        # (frames, H, W, C). SeedVR2 consumes that as one video.\n        images = images.unsqueeze(0)\n    elif images.dim() != 5:","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_seedvr.py#L79-L115","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Check the wiring: connect a LoadImage/LoadVideo IMAGE output, not a LATENT or MASK.","In custom code, print images.dim() and images.shape right before the node call to confirm rank."],"exampleFix":"# before\nimg = img.squeeze(0)  # now (H, W, C), 3-D -> error\nout = seedvr_node(img)\n\n# after\nif img.dim() == 3:\n    img = img.unsqueeze(0)  # (1, H, W, C)\nout = seedvr_node(img)","handlingStrategy":"type-guard","validationCode":"def to_comfy_image(t):\n    if t.dim() == 3:\n        t = t.unsqueeze(0)\n    assert t.dim() in (4, 5), f'expected 4-D/5-D IMAGE, got {tuple(t.shape)}'\n    return t","typeGuard":"def is_comfy_image(t) -> bool:\n    return t.dim() in (4, 5)","tryCatchPattern":null,"preventionTips":["Always materialize images as (N,H,W,C) before wiring into nodes.","Never connect LATENT or MASK outputs into IMAGE inputs.","Log t.dim() in custom nodes that reshape images."],"tags":["seedvr","tensor-shape","image","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}