def is_box_near_crop_edge(boxes: paddle.Tensor,
                          crop_box: List[int],
                          orig_box: List[int],
                          atol: float=20.0) -> paddle.Tensor:
    """Filter masks at the edge of a crop, but not at the edge of the original image."""
    crop_box_paddle = paddle.to_tensor(crop_box, dtype=paddle.float32)
    orig_box_paddle = paddle.to_tensor(orig_box, dtype=paddle.float32)
    boxes = uncrop_boxes_xyxy(boxes, crop_box).astype(paddle.float32)
    near_crop_edge = paddle.isclose(
        boxes, crop_box_paddle[None, :].expand_as(boxes), atol=atol, rtol=0.0)
    near_image_edge = paddle.isclose(
        boxes, orig_box_paddle[None, :].expand_as(boxes), atol=atol, rtol=0.0)
    near_crop_edge = paddle.logical_and(near_crop_edge, ~near_image_edge)
    return paddle.any(near_crop_edge, axis=1)
Filter masks at the edge of a crop, but not at the edge of the original image.
contrib/SegmentAnything/segment_anything/utils/amg.py