Detectron2 模型未生成任何结果

Detectron2 models not generating any results

我只是用下面的一些基本代码来试用 detectron2

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)

但是该模型没有产生任何有意义的预测

[{'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)])}]

我不太明白哪里出了问题,detectron2 documentation 中指出:

You can also run inference directly like this:

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

For inference of builtin models, only “image” key is required, and “width/height” are optional.

在这种情况下,我似乎无法在此处找到丢失的 link。

我遇到了同样的问题,对我来说,我有两个问题需要解决。第一个是调整最短边的大小。我使用了 detectron2.data.transforms 中的 Detectron2 内置函数并导入了 ResizeShortestEdge。可以使用 cfg.INPUT 找到模型值,它将列出 max/min 用于测试和训练的大小。另一个问题是将颜色通道与 cfg 匹配。