>>> draw = ImageDraw.Draw(im)

>>> scores = results["scores"].tolist()
>>> labels = results["labels"].tolist()
>>> boxes = results["boxes"].tolist()

>>> for box, score, label in zip(boxes, scores, labels):
...     xmin, ymin, xmax, ymax = box
...     draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
...     draw.text((xmin, ymin), f"{text_queries[label]}: {round(score,2)}", fill="white")

>>> im
```

<div class="flex justify-center">
     <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/zero-sh-obj-detection_4.png" alt="Beach photo with detected objects"/>
</div>

## Batch processing

You can pass multiple sets of images and text queries to search for different (or same) objects in several images.
Let's use both an astronaut image and the beach image together.
For batch processing, you should pass text queries as a nested list to the processor and images as lists of PIL images,
PyTorch tensors, or NumPy arrays.

```py
>>> images = [image, im]
>>> text_queries = [
...     ["human face", "rocket", "nasa badge", "star-spangled banner"],
...     ["hat", "book", "sunglasses", "camera"],
... ]
>>> inputs = processor(text=text_queries, images=images, return_tensors="pt")
```

Previously for post-processing you passed the single image's size as a tensor, but you can also pass a tuple, or, in case
of several images, a list of tuples. Let's create predictions for the two examples, and visualize the second one (`image_idx = 1`).

```py
>>> with torch.no_grad():
...     outputs = model(**inputs)
...     target_sizes = [x.size[::-1] for x in images]
...     results = processor.post_process_object_detection(outputs, threshold=0.1, target_sizes=target_sizes)

>>> image_idx = 1
>>> draw = ImageDraw.Draw(images[image_idx])

>>> scores = results[image_idx]["scores"].tolist()
>>> labels = results[image_idx]["labels"].tolist()
>>> boxes = results[image_idx]["boxes"].tolist()
The context provides a detailed explanation of how to perform batch processing with images and text queries. It explains that text queries should be passed as a nested list to the processor, which allows for searching different or the same objects across multiple images. This setup is necessary for the processor to handle multiple sets of queries corresponding to different images, ensuring that each image can be processed with its specific set of queries. The context clearly outlines the process and the reason for using a nested list, which directly answers the question about the purpose of passing text queries as a nested list in batch processing.


This question is quite useful for machine learning developers working with NLP applications in the Hugging Face ecosystem. Understanding the purpose of passing text queries as a nested list in batch processing is important for efficiently handling multiple inputs at once, which can significantly improve the performance and scalability of NLP models. It also touches on practical implementation details that developers need to consider when working with batch processing, a common practice in machine learning to optimize computational resources and speed up processing times.


The question is asking about the purpose of a specific method (passing text queries as a nested list) in the context of batch processing. While it does not explicitly mention a specific context or document, it assumes the reader has some understanding of batch processing and why text queries might be passed in a certain format. However, the question is clear and can be understood by someone familiar with batch processing concepts, making it relatively context-independent.

