Fix image post-processing for OWLv2
Author: jla524
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes #30131 (issue)

## Who can review?

@NielsRogge @nisyad-ms

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_30686). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

> Looks great - thanks for taking the time to update the example as well!
> 
> Technically this is a breaking change. However, as many users have highlighted this confusing behaviour and it should always have been done in the post-processing method, I think it's OK to add directly.
> 
> Final request is to add a [test here](https://github.com/huggingface/transformers/blob/508c0bfe555936fc772cd000e2e8da739f777a4f/tests/models/owlv2/test_image_processor_owlv2.py#L86) so that we check the images and boxes are rescaled as expected in the post processing method. Once that's done I think we're good to merge!

Added a test for the resize. I'm not sure if this is the right approach. Let me know what you think!

> Looks great - thanks for iterating on this!
> 
> For the test, have you visualized the bounding boxes to confirm they are sensible? It would be good to check this + bboxes on the examples to make sure everything is a-ok before merge. Otherwise looks good to go!

Yes, the boxes look reasonable. One thing to note is that the box on the right is slightly out of bound. The box has a `x_max` of 642.32, whereas the image itself is 640 pixels.

![image](https://github.com/huggingface/transformers/assets/39754370/675a674b-201b-4007-b314-611c64190dbf)


Hi @jla524 Thank you for the fix.

Our doctesting for this model now has one failure. See below.

> python3 -m pytest -v --make-reports doc_tests_gpu_docs_source_en_model_doc_owlv2.md --doctest-modules docs/source/en/model/doc/owlv2.md failures:
owlv2.md -sv --doctest-continue-on-failure --doctest-glob="*.md"

(on a T4 GPU machine)

I think it's expected? Would you like to take a look to confirm and open a pull request to update `docs/source/en/model/doc/owlv2.md` if that is the way to go?

```
Expected:
    Detected a photo of a cat with confidence 0.614 at location [341.67, 17.54, 642.32, 278.51]
    Detected a photo of a cat with confidence 0.665 at location [6.75, 38.97, 326.62, 354.85]
Got:
    Detected a photo of a cat with confidence 0.614 at location [341.67, 23.39, 642.32, 371.35]
    Detected a photo of a cat with confidence 0.665 at location [6.75, 51.96, 326.62, 473.13]
```

@ydshieh Yes, I'll send in a PR to fix this.