{"record":{"id":"763ed6625dbb85f9","repo":"Comfy-Org/ComfyUI","slug":"unsupported-process-res-method-method","errorCode":null,"errorMessage":"Unsupported process_res_method: {method}","messagePattern":"Unsupported process_res_method: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/depth_anything_3/preprocess.py","lineNumber":36,"sourceCode":"def _round_to_patch(x: int, patch: int = PATCH_SIZE) -> int:\n    down = (x // patch) * patch\n    up = down + patch\n    return up if abs(up - x) <= abs(x - down) else down\n\n\ndef compute_target_size(orig_h: int, orig_w: int, process_res: int, method: str = \"upper_bound_resize\") -> Tuple[int, int]:\n    \"\"\"Compute (target_h, target_w) for a single image.\n    upper_bound_resize: scale longest side to process_res, then round each dim to nearest multiple of 14 (default upstream method).\n    lower_bound_resize: scale shortest side to process_res, then round.\"\"\"\n\n    if method == \"upper_bound_resize\":\n        longest = max(orig_h, orig_w)\n        scale = process_res / float(longest)\n    elif method == \"lower_bound_resize\":\n        shortest = min(orig_h, orig_w)\n        scale = process_res / float(shortest)\n    else:\n        raise ValueError(f\"Unsupported process_res_method: {method}\")\n\n    new_w = max(1, _round_to_patch(int(round(orig_w * scale))))\n    new_h = max(1, _round_to_patch(int(round(orig_h * scale))))\n    return new_h, new_w\n\n\ndef preprocess_image(image: torch.Tensor, process_res: int = 504, method: str = \"upper_bound_resize\") -> torch.Tensor:\n    assert image.ndim == 4 and image.shape[-1] == 3, f\"expected (B,H,W,3) IMAGE; got {tuple(image.shape)}\"\n    B, H, W, _ = image.shape\n    target_h, target_w = compute_target_size(H, W, process_res, method)\n\n    # (B, H, W, 3) -> (B, 3, H, W)\n    x = image.movedim(-1, 1).contiguous()\n    if (target_h, target_w) != (H, W):\n        # Upstream uses cv2 INTER_CUBIC (upscale) / INTER_AREA (downscale).\n        # Lanczos in ``common_upscale`` is anti-aliased and produces the\n        # closest pixel-wise match in a sweep across {bilinear, bicubic,\n        # area, lanczos, bislerp}. Used in both directions for simplicity.","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/depth_anything_3/preprocess.py#L18-L54","documentation":"compute_target_size() chooses a resolution-scaling rule by method string: 'upper_bound_resize' (scale longest side to process_res) or 'lower_bound_resize' (scale shortest side). Any other string raises ValueError. Callers normally pass the default, so the error appears only when a custom method string is forwarded.","triggerScenarios":"Calling preprocess_image()/compute_target_size() with method set to a value other than the two supported strings — e.g. a custom node exposing a free-text combo, or code copied from upstream that used a different method name like 'keep_aspect'.","commonSituations":"Custom nodes wrapping DA3 preprocessing with user-visible method dropdowns; drifting method names between upstream repo and this port.","solutions":["Use \"upper_bound_resize\" (default) or \"lower_bound_resize\" exactly.","If exposing the option in a node, make it a fixed combo of the two supported values rather than free text.","Map/normalize any upstream method name to one of the two supported values at the node boundary."],"exampleFix":"# before\nh, w = compute_target_size(H, W, 504, method=\"fit_longest\")\n\n# after\nh, w = compute_target_size(H, W, 504, method=\"upper_bound_resize\")","handlingStrategy":"type-guard","validationCode":"assert method in (\"upper_bound_resize\", \"lower_bound_resize\"), f\"unsupported method {method!r}\"","typeGuard":"def is_supported_resize_method(method: str) -> bool:\n    return method in {\"upper_bound_resize\", \"lower_bound_resize\"}","tryCatchPattern":null,"preventionTips":["Expose method options as a fixed combo/dropdown of the two supported values.","Normalize upstream method names to this port's vocabulary at the boundary."],"tags":["depth-anything-3","preprocess","input-validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}