Skip to content

Instantly share code, notes, and snippets.

@sprintr
Last active April 26, 2022 16:27
Show Gist options
  • Save sprintr/4dc01ee157312cbf320628eceb2c0c58 to your computer and use it in GitHub Desktop.
Save sprintr/4dc01ee157312cbf320628eceb2c0c58 to your computer and use it in GitHub Desktop.
Bounding Box Regression
# The actual height and width of each cell
cell_height, cell_width = 256, 256
# Bounding box parameters normalized between 0 and 1
# This comes from the output of a bounding box regression model
bx, by, bh, bw = 0.6, 0.6, 0.4, 0.4
# Calculate height and width
height = cell_height * bh
width = cell_width * bw
# Calculate x and y
x = (cell_width * bx) - width / 2
y = (cell_height * by) - height / 2
# Print the final output
print("cell_height = {}, cell_width = {}".format(cell_height, cell_width))
print("bx = {}, by = {}, bh = {}, bw = {}".format(bx, by, bh, bw))
print("height = {}, width = {}".format(height, width))
print("x = {}, y = {}".format(x, y))
# >> cell_height = 256, cell_width = 256
# >> bx = 0.6, by = 0.6, bh = 0.4, bw = 0.4
# >> height = 102.4, width = 102.4
# >> x = 102.39999999999999, y = 102.39999999999999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment