python-3.x - 从 Detectron2 中提取对象特征

标签 python-3.x pytorch faster-rcnn detectron

我对物体检测真的很陌生,如果这个问题看起来太明显了,我很抱歉。

我在检测对象的 detectron2 上有一个训练有素的 FasterRCNN 模型,我正在尝试提取每个检测到的对象的特征以作为模型预测的输出。可用的教程似乎在寻找 ROI 并做出新的预测,以及它们的框和功能。我有推断的盒子,我只需要提取每个盒子的特征。我在下面添加了我一直在使用的代码。谢谢

# Preprocessing
images = predictor.model.preprocess_image(inputs)  # don't forget to preprocess
# Run Backbone Res1-Res4
features = predictor.model.backbone(images.tensor)  # set of cnn features
        
#get proposed boxes + rois + features + predictions
# Run RoI head for each proposal (RoI Pooling + Res5)
proposal_boxes = [x.proposal_boxes for x in proposals]
features = [features[f] for f in predictor.model.roi_heads.in_features]
proposal_rois = predictor.model.roi_heads.box_pooler(features, proposal_boxes)
box_features = predictor.model.roi_heads.box_head(proposal_rois)
predictions = predictor.model.roi_heads.box_predictor(box_features)#found here: https://detectron2.readthedocs.io/_modules/detectron2/modeling/roi_heads/roi_heads.html        
pred_instances, pred_inds = predictor.model.roi_heads.box_predictor.inference(predictions, proposals)
pred_instances = predictor.model.roi_heads.forward_with_given_boxes(features, pred_instances)


# output boxes, masks, scores, etc
pred_instances = predictor.model._postprocess(pred_instances, inputs, images.image_sizes)  # scale box to orig size
# features of the proposed boxes
feats = box_features[pred_inds]
proposal_boxes = proposals[0].proposal_boxes[pred_inds]

最佳答案

这个问题已经在本期讨论得很好:https://github.com/facebookresearch/detectron2/issues/5 .

documentation还解释了如何实现这一目标。

关于python-3.x - 从 Detectron2 中提取对象特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64951289/

相关文章:

python-3.x - 预期尺寸为 5,但得到形状为 (10000, 64, 173, 1) 的数组(GTZAN 数据集上的 CNN + LSTM)

python - net.forward()的返回类型

python - 查找一定范围内有间隙的子列表

python - 如何将日期列添加到Python中已有的时间列?

machine-learning - 访问经过训练的自动编码器的降维

python - 如何在图中获取所有张量?

python - 使用更快的 RCNN Inception Resnet 进行迁移学习 |为什么在第一个检查点之后的每个步骤都会保存新的检查点?

python-3.x - 根据 Python 中的条件复制并粘贴值

python-3.x - 如何在使用 aiohttp session.get 发出请求时发送 etag 或上次修改

pytorch - CUDA 与 DataParallel : Why the difference?