def _transform_boxes_crop_to_aspect_ratio(
        self, boxes, input_height, input_width
    ):
        """Transforms bounding boxes for cropping to aspect ratio."""
        ops = self.backend
        source_aspect_ratio = input_width / input_height
        target_aspect_ratio = self.width / self.height
        new_width = ops.numpy.where(
            source_aspect_ratio > target_aspect_ratio,
            self.height * source_aspect_ratio,
            self.width,
        )
        new_height = ops.numpy.where(
            source_aspect_ratio > target_aspect_ratio,
            self.height,
            self.width / source_aspect_ratio,
        )
        scale_x = new_width / input_width
        scale_y = new_height / input_height
        crop_left = (new_width - self.width) // 2
        crop_top = (new_height - self.height) // 2
        return ops.numpy.stack(
            [
                boxes[..., 0] * scale_x - crop_left,
                boxes[..., 1] * scale_y - crop_top,
                boxes[..., 2] * scale_x - crop_left,
                boxes[..., 3] * scale_y - crop_top,
            ],
            axis=-1,
        )
Transforms bounding boxes for cropping to aspect ratio.
keras/src/layers/preprocessing/image_preprocessing/resizing.py