Comfy-Org/ComfyUI · error · ValueError

The mask is empty, so there is nothing to {action}. Masks ar

Error message

The mask is empty, so there is nothing to {action}. Masks are binarized at 50%: areas painted at less than half opacity are ignored.

What it means

Bria mask inputs are binarized at 50% opacity ((mask > 0.5).float()) before upload. If no pixel survives that threshold the mask is empty, and the node raises instead of sending Bria a mask that selects nothing (which would no-op or error server-side).

Source

Thrown at comfy_api_nodes/nodes_bria.py:272

                visual_input_content_moderation=moderation.get("visual_input_moderation", False),
                visual_output_content_moderation=moderation.get("visual_output_moderation", False),
                seed=seed,
            ),
            response_model=BriaStatusResponse,
        )
        response = await poll_op(
            cls,
            ApiEndpoint(path=f"/proxy/bria/v2/status/{response.request_id}"),
            status_extractor=lambda r: r.status,
            response_model=BriaRemoveBackgroundResponse,
        )
        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(

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Repaint the mask with full (or >50%) opacity in the affected areas.
  2. Check the mask tensor's actual min/max (e.g. print mask.min(), mask.max()) to confirm it is in [0,1] and exceeds 0.5 somewhere.
  3. If the mask is inverted, invert it before feeding the node (mask = 1.0 - mask).

Example fix

# before
binary = (mask > 0.5).float()  # all zeros -> error
# after
mask = torch.clamp(mask, 0, 1)
if (mask > 0.5).any():
    binary = (mask > 0.5).float()
Defensive patterns

Strategy: validation

Validate before calling

if not (mask > 0.5).any():
    raise UserError('Mask has no pixels above 50% opacity - repaint before running.')

Type guard

def mask_is_effective(mask: torch.Tensor) -> bool:
    return bool((mask > 0.5).any().item())

Prevention

When it happens

Trigger: Calling _mask_to_binary_image with a mask tensor whose every value is <= 0.5: fully black mask, mask painted with low-opacity brush strokes, or mask in [0,0.5] range after a bad conversion.

Common situations: User paints a mask at 30% opacity in the mask editor; upstream node outputs a normalized-but-inverted mask; mask tensor scaled to a range below 0.5 (e.g. 0-255 values divided wrong).

Related errors


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