Learn Before
Code

Bounding Box Format Conversion Code

The conversion between the two bounding box representations can be implemented programmatically. The function box_corner_to_center converts bounding boxes from the two-corner representation to the center-width-height presentation. Conversely, box_center_to_corner performs the reverse operation. Both functions expect the input boxes to be a two-dimensional tensor of shape (n,4)(n, 4), where nn is the number of bounding boxes. They utilize standard tensor operations to calculate the midpoints, widths, and heights, and then stack the results along the final axis to return the transformed coordinates.

0

1

Updated 2026-05-19

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L