def convert_format(
    boxes, source, target, height=None, width=None, dtype="float32"
):
    """Converts bounding boxes between formats.

    Supported formats (case-insensitive):
    `"xyxy"`: [left, top, right, bottom]
    `"yxyx"`: [top, left, bottom, right]
    `"xywh"`: [left, top, width, height]
    `"center_xywh"`: [center_x, center_y, width, height]
    `"center_yxhw"`: [center_y, center_x, height, width]
    `"rel_xyxy"`, `"rel_yxyx"`, `"rel_xywh"`, `"rel_center_xywh"`:  Relative
        versions of the above formats, where coordinates are normalized
        to the range [0, 1] based on the image `height` and `width`.

    Args:
        boxes: Bounding boxes tensor/array or dictionary of `boxes` and
            `labels`.
        source: Source format string.
        target: Target format string.
        height: Image height (required for relative target format).
        width: Image width (required for relative target format).
        dtype: Data type for conversion (optional).

    Returns:
        Converted boxes.

    Raises:
        ValueError: For invalid formats, shapes, or missing dimensions.

    Example:
    ```python
    boxes = np.array([[10, 20, 30, 40], [50, 60, 70, 80]])
    # Convert from 'xyxy' to 'xywh' format
    boxes_xywh = keras.utils.bounding_boxes.convert_format(
        boxes, source='xyxy', target='xywh'
    )  # Output: [[10. 20. 20. 20.], [50. 60. 20. 20.]]

    # Convert to relative 'rel_xyxy' format
    boxes_rel_xyxy = keras.utils.bounding_boxes.convert_format(
        boxes, source='xyxy', target='rel_xyxy', height=200, width=300
    ) # Output: [[0.03333334 0.1        0.1        0.2       ],
               #[0.16666667 0.3        0.23333333 0.4       ]]
    ```
    """
    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")
    boxes = box_utils.convert_format(
        boxes=boxes,
        source=source,
        target=target,
        height=height,
        width=width,
        dtype=dtype,
    )
    # Switch back to original backend
    box_utils.backend.reset()
    return boxes
Converts bounding boxes between formats.

    Supported formats (case-insensitive):
    `"xyxy"`: [left, top, right, bottom]
    `"yxyx"`: [top, left, bottom, right]
    `"xywh"`: [left, top, width, height]
    `"center_xywh"`: [center_x, center_y, width, height]
    `"center_yxhw"`: [center_y, center_x, height, width]
    `"rel_xyxy"`, `"rel_yxyx"`, `"rel_xywh"`, `"rel_center_xywh"`:  Relative
        versions of the above formats, where coordinates are normalized
        to the range [0, 1] based on the image `height` and `width`.

    Args:
        boxes: Bounding boxes tensor/array or dictionary of `boxes` and
            `labels`.
        source: Source format string.
        target: Target format string.
        height: Image height (required for relative target format).
        width: Image width (required for relative target format).
        dtype: Data type for conversion (optional).

    Returns:
        Converted boxes.

    Raises:
        ValueError: For invalid formats, shapes, or missing dimensions.

    Example:
    ```python
    boxes = np.array([[10, 20, 30, 40], [50, 60, 70, 80]])
    # Convert from 'xyxy' to 'xywh' format
    boxes_xywh = keras.utils.bounding_boxes.convert_format(
        boxes, source='xyxy', target='xywh'
    )  # Output: [[10. 20. 20. 20.], [50. 60. 20. 20.]]

    # Convert to relative 'rel_xyxy' format
    boxes_rel_xyxy = keras.utils.bounding_boxes.convert_format(
        boxes, source='xyxy', target='rel_xyxy', height=200, width=300
    ) # Output: [[0.03333334 0.1        0.1        0.2       ],
               #[0.16666667 0.3        0.23333333 0.4       ]]
    ```
    
keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/converters.py