in optimum/amd/ryzenai/models/detection_utils.py [0:0]
def scale_coords(current_shape, target_shape, coords):
scaling_ratio = max(target_shape[0] / current_shape[0], target_shape[1] / current_shape[1])
padding_height, padding_width = [
(current - target / scaling_ratio) / 2 for target, current in zip(target_shape, current_shape)
]
coords[:, [0, 2]] = (coords[:, [0, 2]] - padding_width) * scaling_ratio
coords[:, [1, 3]] = (coords[:, [1, 3]] - padding_height) * scaling_ratio
coords[:, 0].clamp_(0, target_shape[1])
coords[:, 1].clamp_(0, target_shape[0])
coords[:, 2].clamp_(0, target_shape[1])
coords[:, 3].clamp_(0, target_shape[0])
return coords