0
0
PyTorchml~10 mins

Bounding box handling in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the width of a bounding box.

PyTorch
width = bbox[[1]] - bbox[0]
Drag options to blanks, or click blank then click option'
A2
B4
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong index for x_max.
Subtracting y-coordinates instead of x-coordinates.
2fill in blank
medium

Complete the code to compute the area of a bounding box.

PyTorch
area = (bbox[2] - bbox[0]) * (bbox[[1]] - bbox[1])
Drag options to blanks, or click blank then click option'
A3
B2
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong index for y_max.
Forgetting to subtract y_min from y_max.
3fill in blank
hard

Fix the error in the code to correctly compute the center of a bounding box.

PyTorch
center_x = (bbox[0] + bbox[[1]]) / 2
Drag options to blanks, or click blank then click option'
A3
B2
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using y-coordinates instead of x-coordinates.
Using the wrong index for x_max.
4fill in blank
hard

Fill both blanks to create a dictionary of bounding box widths and heights for a list of boxes.

PyTorch
sizes = {i: (bbox[[1]] - bbox[0], bbox[[2]] - bbox[1]) for i, bbox in enumerate(boxes)}
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up x and y indices.
Using y_min or x_min incorrectly.
5fill in blank
hard

Fill all three blanks to filter bounding boxes with area greater than 1000 and create a dictionary of their centers.

PyTorch
centers = {i: ((bbox[[1]] + bbox[0]) / 2, (bbox[[2]] + bbox[[3]]) / 2) for i, bbox in enumerate(boxes) if (bbox[2] - bbox[0]) * (bbox[3] - bbox[1]) > 1000}
Drag options to blanks, or click blank then click option'
A2
B1
C3
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up indices for y_min and y_max.
Using width or height instead of center coordinates.