mmdetection怎么生成特征图而非热力图
时间: 2024-05-04 22:12:43 浏览: 10
根据提供的引用内容,可以得知在mmdetection中生成特征图的方法是在前向传播时将四个stage的特征图返回出来。具体实现方法如下:
1.在mmdetection的two_stage.py文件中进行修改,将forward函数中的返回值改为四个stage的特征图,代码如下:
```python
def forward(self, img, img_metas, **kwargs):
x = self.extract_feat(img)
proposal_list = self.rpn_head.simple_test_rpn(x, img_metas)
if self.with_bbox or self.with_mask:
if self.with_shared_head:
x = self.shared_head(x)
outs = self.bbox_head(x)
bbox_results = self.bbox_head.get_bboxes(
proposal_list,
outs,
img_metas,
cfg=self.test_cfg,
rescale=self.with_bbox_rescale)
if self.with_mask:
mask_results = self.mask_head(x, bbox_results)
# 返回四个stage的特征图
return x[0], x[1], x[2], x[3]
```
2.在使用mmdetection进行目标检测时,可以通过修改配置文件来开启返回特征图的功能。具体方法是在配置文件中添加以下代码:
```python
# 在测试时返回特征图
test_cfg = dict(
rcnn=dict(
with_mask=True,
# 返回四个stage的特征图
extra_test_outputs=['conv_feat', 'conv_feat2', 'conv_feat3', 'conv_feat4']
)
)
```
通过以上两个步骤,就可以在mmdetection中生成特征图而非热力图了。