import torch


def prepare_gt(input_img, gt_bboxes, gt_classes):
    """
    args:
    - input_img: PIL image HxW
    - gt_bboxes - list of bounding boxes
    - gt_classes - list of category ids

    return:
    gt[0] = tensor of bboxes of objects in image scaled [0,1], in (CENTER, w, h) format
    gt[1] = tensor of class ids in image
    """
    gt = [torch.FloatTensor(gt_bboxes), torch.IntTensor(gt_classes)]
    height, width, _ = input_img.shape

    for idx, bbox in enumerate(gt[0]):
        new_bbox = [0] * 4
        new_bbox[0] = (bbox[0] + (bbox[2] / 2)) / width
        new_bbox[1] = (bbox[1] + (bbox[3] / 2)) / height
        new_bbox[2] = bbox[2] / width
        new_bbox[3] = bbox[3] / height
        gt[0][idx] = torch.FloatTensor(new_bbox)

    return gt