tf.keras.utils.bounding_boxes.encode_box_to_deltas
Stay organized with collections
Save and categorize content based on your preferences.
Encodes bounding boxes relative to anchors as deltas.
tf.keras.utils.bounding_boxes.encode_box_to_deltas(
anchors,
boxes,
anchor_format,
box_format,
encoding_format='center_yxhw',
variance=None,
image_shape=None
)
This function calculates the deltas that represent the difference between
bounding boxes and provided anchors. Deltas encode the offsets and scaling
factors to apply to anchors to obtain the target boxes.
Boxes and anchors are first converted to the specified encoding_format
(defaulting to center_yxhw) for consistent delta representation.
Args |
anchors
|
Tensors. Anchor boxes with shape of (N, 4) where N is the
number of anchors.
|
boxes
|
Tensors Bounding boxes to encode. Boxes can be of shape
(B, N, 4) or (N, 4).
|
anchor_format
|
str. The format of the input anchors
(e.g., "xyxy", "xywh", etc.).
|
box_format
|
str. The format of the input boxes
(e.g., "xyxy", "xywh", etc.).
|
encoding_format
|
str. The intermediate format to which boxes and anchors
are converted before delta calculation. Defaults to "center_yxhw".
|
variance
|
List[float]. A 4-element array/tensor representing variance
factors to scale the box deltas. If provided, the calculated deltas
are divided by the variance. Defaults to None.
|
image_shape
|
Tuple[int]. The shape of the image (height, width, 3).
When using relative bounding box format for box_format the
image_shape is used for normalization.
|
Returns |
Encoded box deltas. The return type matches the encode_format.
|
Raises |
ValueError
|
If variance is not None and its length is not 4.
|
ValueError
|
If encoding_format is not "center_xywh" or
"center_yxhw".
|
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]