Comfy-Org/ComfyUI · error · ValueError
Invalid image dimensions
Error message
Invalid image dimensions
What it means
ValueError from validate_images_aspect_ratio_closeness when either of the two compared images has a non-positive dimension (min(w1,h1,w2,h2) <= 0). The function computes closeness C = max(ar1,ar2)/min(ar1,ar2), which is undefined for degenerate tensors, so it rejects them before dividing. Unlike validate_image_aspect_ratio, the message does not include the values.
Source
Thrown at comfy_api_nodes/util/validation_utils.py:70
def validate_images_aspect_ratio_closeness(
first_image: torch.Tensor,
second_image: torch.Tensor,
min_rel: float, # e.g. 0.8
max_rel: float, # e.g. 1.25
*,
strict: bool = False, # True -> (min, max); False -> [min, max]
) -> float:
"""
Validates that the two images' aspect ratios are 'close'.
The closeness factor is C = max(ar1, ar2) / min(ar1, ar2) (C >= 1).
We require C <= limit, where limit = max(max_rel, 1.0 / min_rel).
Returns the computed closeness factor C.
"""
w1, h1 = get_image_dimensions(first_image)
w2, h2 = get_image_dimensions(second_image)
if min(w1, h1, w2, h2) <= 0:
raise ValueError("Invalid image dimensions")
ar1 = w1 / h1
ar2 = w2 / h2
closeness = max(ar1, ar2) / min(ar1, ar2)
limit = max(max_rel, 1.0 / min_rel)
if (closeness >= limit) if strict else (closeness > limit):
raise ValueError(
f"Aspect ratios must be close: ar1/ar2={ar1/ar2:.2g}, "
f"allowed range {min_rel}–{max_rel} (limit {limit:.2g})."
)
return closeness
def validate_aspect_ratio_string(
aspect_ratio: str,
min_ratio: tuple[float, float] | None = None, # e.g. (1, 4)
max_ratio: tuple[float, float] | None = None, # e.g. (4, 1)
*,
strict: bool = False, # True -> (min, max); False -> [min, max]View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Verify both tensors have strictly positive H and W before pairing them.
- Fix the crop/slice code that emptied one image.
- Add a shape assertion in the calling node so failures point at the right tensor.
Defensive patterns
Strategy: validation
Validate before calling
def pair_has_positive_dims(a: torch.Tensor, b: torch.Tensor) -> bool:
return all(min(t.shape[-2], t.shape[-3]) > 0 for t in (a, b)) Prevention
- Validate both tensors' shapes before pairing images
- Log shapes when pairing fails to identify the degenerate input
When it happens
Trigger: Calling validate_images_aspect_ratio_closeness(first, second, min_rel, max_rel) where first or second has a zero-sized dimension (bad slice, empty batch element).
Common situations: Comparing a generated image with a reference that was cropped to nothing; empty tensor from a failed loader; slicing bugs in custom pairing nodes.
Related errors
- Invalid image tensor shape.
- Invalid image dimensions: {w}x{h}
- JoyImage reference inputs must contain one image each
- The maximum number of reference images is 10.
- sync.so rejects images above 4K (4096x2160); got {width}x{he
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/06c4b12ee3479be4.
Report an issue: GitHub.