Bounding box normalization

#3
by Rivoks - opened

Hello,

It seems that he demo code for OWLv2 has an issue with the image normalization. The helper function get_preprocessed_image doesn't work.
This code section works to normalize the bounding box coordinates:

# Utility function for OWL-v2
# See https://github.com/huggingface/transformers/issues/30131#issuecomment-2097490581
def get_normalized_bbox(image, bbox):
    width, height = image.size

    width_ratio = 1
    height_ratio = 1

    if width < height:
        width_ratio = width / height
    elif height < width:
        height_ratio = height / width
    
    xmin, ymin, xmax, ymax = bbox
    xmin /= width_ratio
    ymin /= height_ratio
    xmax /= width_ratio
    ymax /= height_ratio
    
    return [xmin, ymin, xmax, ymax]
    

Is it possible to update the README.md ? (I can make a PR if needed)

Kind regards,
Yazid

Sign up or log in to comment