def crop_mask(masks, boxes):
    """
    It takes a mask and a bounding box, and returns a mask that is cropped to the bounding box

    Args:
      masks (paddle.Tensor): [h, w, n] tensor of masks
      boxes (paddle.Tensor): [n, 4] tensor of bbox coordinates in relative point form

    Returns:
      (paddle.Tensor): The masks are being cropped to the bounding box.
    """
    _, h, w = masks.shape
    x1, y1, x2, y2 = paddle.chunk(boxes[:, :, None], 4, axis=1)
    r = paddle.arange(w, dtype=x1.dtype)[None, None, :]
    c = paddle.arange(h, dtype=y1.dtype)[None, :, None]
    if "npu" in paddle.device.get_all_custom_device_type():
        # bool tensor broadcast multiply is extreamly slow on npu, so we cast it to float32.
        m_dtype = masks.dtype
        return masks * ((r >= x1).cast(m_dtype) * (r < x2).cast(m_dtype) *
                        (c >= y1).cast(m_dtype) * (c < y2).cast(m_dtype))
    else:
        return masks * ((r >= x1) * (r < x2) * (c >= y1) *
                        (c < y2)).astype(masks.dtype)

    It takes a mask and a bounding box, and returns a mask that is cropped to the bounding box

    Args:
      masks (paddle.Tensor): [h, w, n] tensor of masks
      boxes (paddle.Tensor): [n, 4] tensor of bbox coordinates in relative point form

    Returns:
      (paddle.Tensor): The masks are being cropped to the bounding box.
    
ppdet/modeling/heads/ppyoloe_ins_head.py