point_rcnn.py 2.39 KB
Newer Older
1
# Copyright (c) OpenMMLab. All rights reserved.
2
3
from typing import Dict, Optional

4
5
import torch

6
from mmdet3d.registry import MODELS
7
8
9
from .two_stage import TwoStage3DDetector


10
@MODELS.register_module()
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class PointRCNN(TwoStage3DDetector):
    r"""PointRCNN detector.

    Please refer to the `PointRCNN <https://arxiv.org/abs/1812.04244>`_

    Args:
        backbone (dict): Config dict of detector's backbone.
        neck (dict, optional): Config dict of neck. Defaults to None.
        rpn_head (dict, optional): Config of RPN head. Defaults to None.
        roi_head (dict, optional): Config of ROI head. Defaults to None.
        train_cfg (dict, optional): Train configs. Defaults to None.
        test_cfg (dict, optional): Test configs. Defaults to None.
        pretrained (str, optional): Model pretrained path. Defaults to None.
        init_cfg (dict, optional): Config of initialization. Defaults to None.
    """

    def __init__(self,
28
29
30
31
32
33
34
35
                 backbone: dict,
                 neck: Optional[dict] = None,
                 rpn_head: Optional[dict] = None,
                 roi_head: Optional[dict] = None,
                 train_cfg: Optional[dict] = None,
                 test_cfg: Optional[dict] = None,
                 init_cfg: Optional[dict] = None,
                 data_preprocessor: Optional[dict] = None) -> Optional:
36
37
38
39
40
41
42
        super(PointRCNN, self).__init__(
            backbone=backbone,
            neck=neck,
            rpn_head=rpn_head,
            roi_head=roi_head,
            train_cfg=train_cfg,
            test_cfg=test_cfg,
43
44
            init_cfg=init_cfg,
            data_preprocessor=data_preprocessor)
45

46
    def extract_feat(self, batch_inputs_dict: Dict) -> Dict:
47
48
49
        """Directly extract features from the backbone+neck.

        Args:
50
51
52
53
54
            batch_inputs_dict (dict): The model input dict which include
                'points', 'imgs' keys.

                - points (list[torch.Tensor]): Point cloud of each sample.
                - imgs (torch.Tensor, optional): Image of each sample.
55
56

        Returns:
57
            dict: Features from the backbone+neck and raw points.
58
        """
59
        points = torch.stack(batch_inputs_dict['points'])
60
61
62
63
        x = self.backbone(points)

        if self.with_neck:
            x = self.neck(x)
64
65
66
67
        return dict(
            fp_features=x['fp_features'].clone(),
            fp_points=x['fp_xyz'].clone(),
            raw_points=points)