【发布时间】:2020-06-16 04:51:40
【问题描述】:
我正在研究对象检测,我有一个包含图像及其相应边界框(真实值)的数据集。
我实际上已经构建了自己的特征提取器,它将图像作为输入并输出特征图(基本上是一个编码器-解码器系统,其中解码器的最终输出与图像大小相同,并且具有 3 个通道)。现在,我想将此特征图作为输入提供给 FasterRCNN 模型进行检测,而不是原始图像。我正在使用以下代码在 FRCNN 检测模块顶部添加特征图(使用 RTFNet 生成特征图 - 代码在此link)
frcnn_model = fasterrcnn_resnet50_fpn(pretrained=True)
in_features = frcnn_model.roi_heads.box_predictor.cls_score.in_features
frcnn_model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
fpn_block = frcnn_model.backbone.fpn
rpn_block = frcnn_model.rpn
backbone = RTFNet(num_classes) RTFNet is a feature extractor taking as input, an image having 4 channels(fused RGB and thermal image) ,
model = nn.Sequential(backbone, nn.ReLU(inplace=True))
model = nn.Sequential(model,fpn_block)
model = nn.Sequential(model,rpn_block)
model = nn.Sequential(model,FastRCNNPredictor(in_features, num_classes))
我只是想通过使用以下生成随机图像和边界框的代码来测试它是否正常工作
images, boxes = torch.rand(1, 4, 512, 640), torch.rand(4, 11, 4)
labels = torch.randint(1, num_classes, (4, 11))
images = list(image for image in images)
targets = []
for i in range(len(images)):
d = {}
d['boxes'] = boxes[i]
d['labels'] = labels[i]
targets.append(d)
output = model(images, targets)
运行它会给我以下错误
TypeError Traceback (most recent call last)
<ipython-input-22-2637b8c27ad2> in <module>()
----> 1 output = model(images, targets)
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
TypeError: forward() takes 2 positional arguments but 3 were given
但是,当我用普通的 FasterRCNN 模型替换我的模型时,
model = fasterrcnn_resnet50_fpn(pretrained=True)
in_features = model.roi_heads.box_predictor.cls_score.in_features
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
没有错误,工作正常
谁能告诉我哪里出错了?提前致谢
【问题讨论】:
标签: python pytorch object-detection faster-rcnn torchvision