Adding doctest for `object-detection` pipeline.
Author: Narsil
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 # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- 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:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

Comments:
_The documentation is not available anymore as the PR was closed or merged._

> I still think the `candidate_labels` argument/naming is not very aligned with zero-shot object detection but the PR looks good to me otherwise.

Here it's just an alias.
I'm really not sure I understand how it could be a bad name.

The content end up being within `label` section of the output, so saying they are `labels` doesn't seem all that shocking to me.
The fact that they are `candidate` is because there is no guarantee that you will be able to detect them.

Overall I find `candidate_labels` not that bad.

Why I think `text_queries` is not the best choice:
- It is not aligned with other `zero-shot` pipelines
- `text_queries` implies `text` but you're not looking for text within an image but readers might understand this:
   ```pipe(image, text_query="Restaurant")``` Are we looking for places where the text restaurant is written ?
- `queries` implies asking for information so I'm somehow expecting to always receive something, I feel it conveys less well the idea of "potentiality" than `canddiate`.

The main counterargument in the original PR was that `candidate_labels` was using `hypothesis_template`. I feel like it's not really a strong stance, since `hypothesis_template` isn't really meant to be used so much (it's kind of  a power user tool). Even then, I don't think just because there is no `hypothesis_template` should prevent us from using the same name, if the name is readable, and serves the same purpose, then it's a good name, the rest is implementation detail imo.

Happy to hear your thoughts on why you think it fits better.


> Here it's just an alias. I'm really not sure I understand how it could be a bad name.
> 
> Happy to hear your thoughts on why you think it fits better.

@Narsil my main concern is that zero-shot-classification pipeline selects one of the `candidate_labels` to assign a final class / label to the image, whereas zero-shot-object-detection queries the image for each query and might find instances of all query objects. It'd be less confusing to users if we add a better docstring example -> using an image where both candidate_labels=["head", "bird"] are detected instead of just "bird".


> @Narsil my main concern is that zero-shot-classification pipeline selects one of the candidate_labels to assign a final class / label to the image, whereas zero-shot-object-detection queries the image for each query and might find instances of all query objects. It'd be less confusing to users if we add a better docstring example -> using an image where both candidate_labels=["head", "bird"] are detected instead of just "bird".

Oh, but no, `zero-shot-classification` does multi label classification actually. The default is to normalize scores across labels, but it's not mandatory, by default the models can handle multiple label just fine (results tend to be more noisy though).

https://huggingface.co/facebook/bart-large-mnli?candidateLabels=space+%26+cosmos%2C+scientific+discovery%2C+microbiology%2C+robots%2C+archeology&multiClass=true&text=A+new+model+offers+an+explanation+for+how+the+Galilean+satellites+formed+around+the+solar+system%E2%80%99s+largest+world.+Konstantin+Batygin+did+not+set+out+to+solve+one+of+the+solar+system%E2%80%99s+most+puzzling+mysteries+when+he+went+for+a+run+up+a+hill+in+Nice%2C+France.+Dr.+Batygin%2C+a+Caltech+researcher%2C+best+known+for+his+contributions+to+the+search+for+the+solar+system%E2%80%99s+missing+%E2%80%9CPlanet+Nine%2C%E2%80%9D+spotted+a+beer+bottle.+At+a+steep%2C+20+degree+grade%2C+he+wondered+why+it+wasn%E2%80%99t+rolling+down+the+hill.+He+realized+there+was+a+breeze+at+his+back+holding+the+bottle+in+place.+Then+he+had+a+thought+that+would+only+pop+into+the+mind+of+a+theoretical+astrophysicist%3A+%E2%80%9COh%21+This+is+how+Europa+formed.%E2%80%9D+Europa+is+one+of+Jupiter%E2%80%99s+four+large+Galilean+moons.+And+in+a+paper+published+Monday+in+the+Astrophysical+Journal%2C+Dr.+Batygin+and+a+co-author%2C+Alessandro+Morbidelli%2C+a+planetary+scientist+at+the+C%C3%B4te+d%E2%80%99Azur+Observatory+in+France%2C+present+a+theory+explaining+how+some+moons+form+around+gas+giants+like+Jupiter+and+Saturn%2C+suggesting+that+millimeter-sized+grains+of+hail+produced+during+the+solar+system%E2%80%99s+formation+became+trapped+around+these+massive+worlds%2C+taking+shape+one+at+a+time+into+the+potentially+habitable+moons+we+know+today.