FasterRCNN Batch Based Usage

Can we use the Faster-RCNN model of torchvision, batch-based on the inference time?
for example:

import torch
from torchvision import models

model = models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
model.eval()

img = torch.randn(2, 3, 224, 224)  # [N, C, H, W]

pred = model([img])  # Pass the image to the model

the above code has error. Is there any solution to address it and use faster-rcnn batch-based?

Dear @ptrblck,
Would you please kindly answer the above question?

Batching should be done under the hood, if you pass a list of tensors.
self.transform will e.g. resize all tensors to [3, 800, 800] and create a batch as [batch_size, 3, 800, 800].

1 Like