tf.keras.utils.bounding_boxes.clip_to_image_size
Stay organized with collections
Save and categorize content based on your preferences.
Clips bounding boxes to be within the image dimensions.
tf.keras.utils.bounding_boxes.clip_to_image_size(
bounding_boxes,
height=None,
width=None,
bounding_box_format='xyxy'
)
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:
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
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[null,null,["Last updated 2026-10-31 UTC."],[],[]]