def clip_to_image_size(
    bounding_boxes, height=None, width=None, bounding_box_format="xyxy"
):
    """Clips bounding boxes to be within the image dimensions.
    Args:
        bounding_boxes: A dictionary with 'boxes' shape `(N, 4)` or
            `(batch, N, 4)` and 'labels' shape `(N,)` or `(batch, N,)`.
        height: Image height.
        width: Image width.
        bounding_box_format: The format of the input bounding boxes. Defaults to
            `"xyxy"`.

    Returns:
        Clipped bounding boxes.

    Example:
    ```python
    boxes = {"boxes": np.array([[-10, -20, 150, 160], [50, 40, 70, 80]]),
             "labels": np.array([0, 1])}
    clipped_boxes = keras.utils.bounding_boxes.clip_to_image_size(
        boxes, height=100, width=120,
    )
    # Output will have boxes clipped to the image boundaries, and labels
    # potentially adjusted if the clipped area becomes zero
    ```
    """

    box_utils = BoundingBox()
    # Switch to tensorflow backend if we are in tf.data pipe
    if backend_utils.in_tf_graph():
        box_utils.backend.set_backend("tensorflow")
    bounding_boxes = box_utils.clip_to_image_size(
        bounding_boxes,
        height=height,
        width=width,
        bounding_box_format=bounding_box_format,
    )
    # Switch back to original backend
    box_utils.backend.reset()
    return bounding_boxes
Clips bounding boxes to be within the image dimensions.
    Args:
        bounding_boxes: A dictionary with 'boxes' shape `(N, 4)` or
            `(batch, N, 4)` and 'labels' shape `(N,)` or `(batch, N,)`.
        height: Image height.
        width: Image width.
        bounding_box_format: The format of the input bounding boxes. Defaults to
            `"xyxy"`.

    Returns:
        Clipped bounding boxes.

    Example:
    ```python
    boxes = {"boxes": np.array([[-10, -20, 150, 160], [50, 40, 70, 80]]),
             "labels": np.array([0, 1])}
    clipped_boxes = keras.utils.bounding_boxes.clip_to_image_size(
        boxes, height=100, width=120,
    )
    # Output will have boxes clipped to the image boundaries, and labels
    # potentially adjusted if the clipped area becomes zero
    ```
    
keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/converters.py