# How to perform batch inference on GroundingDino model

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-perform-batch-inference-on-groundingdino-model%2F90940%3E%5C
**Category:** 🤗Transformers\
**Created:** [June 7, 2024, 5:30pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-perform-batch-inference-on-groundingdino-model%2F90940 "2024-06-07T17:30:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tariksetia](https://avatars.discourse-cdn.com/v4/letter/t/8edcca/32.png) [@tariksetia](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftariksetia)%5C
**Post date:** [June 7, 2024, 5:30pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-perform-batch-inference-on-groundingdino-model%2F90940%2F1 "2024-06-07T17:30:13Z")

</div>

```auto
frames = [.....List of PIL.Image....]
 inputs = processor(images=frames, text=text, return_tensors="pt").to(device)

with torch.no_grad():
     outputs = model(**inputs)
 print(outputs)

```

Error:  
`RuntimeError: The size of tensor a (3) must match the size of tensor b (6) at non-singleton dimension 2`

---

<div class="post-metadata">

**Author:** ![royve](https://avatars.discourse-cdn.com/v4/letter/r/e5b9ba/32.png) [@royve](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Froyve)%5C
**Post date:** [July 25, 2024, 12:04am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-perform-batch-inference-on-groundingdino-model%2F90940%2F2 "2024-07-25T00:04:52Z")

</div>

I have the same problem… any updates?  
Thanks!

---

<div class="post-metadata">

**Author:** ![qubvel-hf](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/qubvel-hf/32/32371_2.png) [@qubvel-hf](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fqubvel-hf)%5C
**Post date:** [July 25, 2024, 2:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-perform-batch-inference-on-groundingdino-model%2F90940%2F3 "2024-07-25T14:27:36Z")

</div>

Hi @royve, thanks for the question, would be nice to have minimal reproducing example and environment 🙂

I was able to run a batched inference with the following env and code:

```auto
- `transformers` version: 4.44.0.dev0
- Platform: Linux-6.5.0-1020-aws-x86_64-with-glibc2.35
- Python version: 3.10.12
- PyTorch version (GPU?): 2.4.0+cu118 (True)
- GPU type: NVIDIA A10G

```

```python
import requests

import torch
from PIL import Image
from transformers import AutoProcessor, AutoModelForZeroShotObjectDetection

model_id = "IDEA-Research/grounding-dino-tiny"
device = "cuda"

processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)

image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(image_url, stream=True).raw)
images = [image, image]
texts = [
    "a cat. a remote control.",
    "a cat. a remote control. a sofa.",
]

inputs = processor(images=images, text=texts, padding=True, return_tensors="pt").to(device)

with torch.no_grad():
    outputs = model(**inputs)

w, h = image.size
results = processor.post_process_grounded_object_detection(
    outputs,
    inputs.input_ids,
    box_threshold=0.4,
    text_threshold=0.3,
    target_sizes=[(h, w), (h, w)],
)
print(results)

```
