def mask_to_box_coordinate(mask,
                           normalize=False,
                           format="xyxy",
                           dtype="float32"):
    """
    Compute the bounding boxes around the provided mask.
    Args:
        mask (Tensor:bool): [b, c, h, w]

    Returns:
        bbox (Tensor): [b, c, 4]
    """
    assert mask.ndim == 4
    assert format in ["xyxy", "xywh"]

    h, w = mask.shape[-2:]
    y, x = paddle.meshgrid(paddle.arange(end=h, dtype=dtype),
                           paddle.arange(end=w, dtype=dtype))

    x_mask = x * mask.astype(x.dtype)
    x_max = x_mask.flatten(-2).max(-1) + 1
    x_min = paddle.where(mask.astype(bool), x_mask,
                         paddle.to_tensor(1e8)).flatten(-2).min(-1)

    y_mask = y * mask.astype(y.dtype)
    y_max = y_mask.flatten(-2).max(-1) + 1
    y_min = paddle.where(mask.astype(bool), y_mask,
                         paddle.to_tensor(1e8)).flatten(-2).min(-1)
    out_bbox = paddle.stack([x_min, y_min, x_max, y_max], axis=-1)
    mask = mask.any(axis=[2, 3]).unsqueeze(2)
    out_bbox = out_bbox * mask.astype(out_bbox.dtype)
    if normalize:
        out_bbox /= paddle.to_tensor([w, h, w, h]).astype(dtype)

    return out_bbox if format == "xyxy" else bbox_xyxy_to_cxcywh(out_bbox)

    Compute the bounding boxes around the provided mask.
    Args:
        mask (Tensor:bool): [b, c, h, w]

    Returns:
        bbox (Tensor): [b, c, 4]
    
ppdet/modeling/transformers/utils.py