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

  1. Regenerate the mask at the same resolution (or same aspect ratio) as the input image.
  2. Resize the mask to the image's exact dimensions before the node: torch.nn.functional.interpolate(mask, size=(ih, iw)).
  3. 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

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


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/8ffbe2d0eef35fb5. Report an issue: GitHub.