tf.keras.utils.bounding_boxes.encode_box_to_deltas

Encodes bounding boxes relative to anchors as deltas.

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.

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.

Encoded box deltas. The return type matches the encode_format.

ValueError If variance is not None and its length is not 4.
ValueError If encoding_format is not "center_xywh" or "center_yxhw".