adds anchor grid
This commit is contained in:
@@ -9,4 +9,24 @@ def get_anchor_grid(
|
||||
anchor_widths: Sequence[float],
|
||||
aspect_ratios: Sequence[float],
|
||||
) -> np.ndarray:
|
||||
raise NotImplementedError()
|
||||
anchor_grid = np.empty(
|
||||
[len(width), len(ratio), num_rows, num_cols, 4], dtype=int)
|
||||
for width_idx, width in enumerate(anchor_widths):
|
||||
for ratio_idx, ratio in enumerate(aspect_ratios):
|
||||
for row in range(num_rows):
|
||||
for col in range(num_cols):
|
||||
anchor_point = (
|
||||
col * scale_factor + scale_factor/2, row * scale_factor + scale_factor / 2)
|
||||
anchor_grid[width_idx, ratio_idx, row, col] = get_box(
|
||||
width, ratio, anchor_point)
|
||||
|
||||
return anchor_grid
|
||||
|
||||
|
||||
def get_box(width: float, ratio: float, anchor_point: tuple[float, float]) -> np.ndarray:
|
||||
box = np.empty(4)
|
||||
box[0] = anchor_point[0] - (width / 2)
|
||||
box[1] = anchor_point[1] - (width * ratio / 2)
|
||||
box[2] = anchor_point[0] + (width / 2)
|
||||
box[3] = anchor_point[1] + (width * ratio / 2)
|
||||
return box
|
||||
|
||||
Reference in New Issue
Block a user