Comfy-Org/ComfyUI · error · ValueError
Mask must have the same aspect ratio as the image: image is
Error message
Mask must have the same aspect ratio as the image: image is {iw}x{ih}, mask is {mw}x{mh}. What it means
Bria's fill/erase endpoints require the mask to have the same aspect ratio as the image (within a 1% tolerance, checked as abs(iw*mh - ih*mw) > 0.01*ih*mw). A mismatched mask would be applied to the wrong pixel regions, so the node validates before upload.
Source
Thrown at comfy_api_nodes/nodes_bria.py:283
)
return IO.NodeOutput(await download_url_to_image_tensor(response.result.image_url))
def _mask_to_binary_image(mask: Input.Image, action: str) -> torch.Tensor:
binary = (mask > 0.5).float()
if not binary.any():
raise ValueError(
f"The mask is empty, so there is nothing to {action}. Masks are binarized at 50%: "
f"areas painted at less than half opacity are ignored."
)
return convert_mask_to_image(binary)
def _validate_mask_aspect_ratio(image: Input.Image, mask: Input.Image) -> None:
ih, iw = image.shape[1], image.shape[2]
mh, mw = mask.shape[-2], mask.shape[-1]
if abs(iw * mh - ih * mw) > 0.01 * ih * mw:
raise ValueError(f"Mask must have the same aspect ratio as the image: image is {iw}x{ih}, mask is {mw}x{mh}.")
class BriaGenFill(IO.ComfyNode):
@classmethod
def define_schema(cls):
return IO.Schema(
node_id="BriaGenFill",
display_name="Bria Generative Fill",
category="partner/image/Bria",
description="Generate objects or scenery inside a masked region of an image using Bria.",
inputs=[
IO.Image.Input("image"),
IO.Mask.Input(
"mask",
tooltip="White areas are filled with generated content, black areas are preserved. "
"The mask is binarized before sending, so partially painted areas count as white. "
"Must have the same aspect ratio as the image.",View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Regenerate the mask at the same resolution (or same aspect ratio) as the input image.
- Resize the mask to the image's exact dimensions before the node: torch.nn.functional.interpolate(mask, size=(ih, iw)).
- If the image was cropped after masking, crop the mask with identical parameters.
Example fix
# before mask = F.interpolate(mask, size=(256, 512)) # image is 512x512 # after _, _, ih, iw = image.shape[-4:], image.shape[-1] mask = torch.nn.functional.interpolate(mask, size=(image.shape[-2], image.shape[-1]), mode='nearest')
Defensive patterns
Strategy: validation
Validate before calling
ih, iw = image.shape[-2], image.shape[-1] mh, mw = mask.shape[-2], mask.shape[-1] assert abs(iw * mh - ih * mw) <= 0.01 * ih * mw, 'mask aspect ratio differs from image'
Prevention
- Generate the mask from the image itself (same canvas) rather than a separate source.
- Resize masks with the same interpolation parameters as the image in any preprocessing chain.
When it happens
Trigger: Feeding BriaGenFill/BriaErase a mask whose width/height ratio differs from the image by more than 1%: e.g. 512x512 image with a 256x512 mask, or a mask resized non-uniformly upstream.
Common situations: Mask painted on a different canvas size than the current image; image was resized/cropped between mask creation and the Bria node; batch image where mask matches only one frame's shape.
Related errors
- The mask is empty, so there is nothing to {action}. Masks ar
- Bria accepts a width-to-height ratio between {BRIA_MIN_RATIO
- One of prompt or structured_prompt is required to be non-emp
- Bria can upscale up to a maximum output dimension of {BRIA_M
- This image cannot be upscaled by Bria at any multiplier: it
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/8ffbe2d0eef35fb5.
Report an issue: GitHub.