I am just trying out detectron2 with some basic code as follows
model = model_zoo.get('COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml', trained=True)
im = Image.open('input.jpg')
t = transforms.ToTensor()
model.eval()
with torch.no_grad():
im = t(im)
output = model([{'image':im}])
print(output)
However the model does not produce any meaningful predictions
[{'instances': Instances(num_instances=0, image_height=480, image_width=640, fields=[pred_boxes: Boxes(tensor([], device='cuda:0', size=(0, 4))), scores: tensor([], device='cuda:0'), pred_classes: tensor([], device='cuda:0', dtype=torch.int64)])}]
I don't quite get what went wrong, it was stated in the detectron2 documentation that:
You can also run inference directly like this:
model.eval() with torch.no_grad(): outputs = model(inputs)
and
For inference of builtin models, only “image” key is required, and “width/height” are optional.
In which case, I can't seem to find the missing link here.
I had the same issue, for me I had two issues to fix. The first was resizing shortest edge. I used the Detectron2 built function from detectron2.data.transforms and imported ResizeShortestEdge. The model values can be found with cfg.INPUT, which will list max/min sizes for test and train. The other issue was matching the color channels with cfg.