base_3droi_head.py 2.87 KB
Newer Older
wuyuefeng's avatar
wuyuefeng committed
1
from abc import ABCMeta, abstractmethod
2
from mmcv.runner import BaseModule
wuyuefeng's avatar
wuyuefeng committed
3
4


5
class Base3DRoIHead(BaseModule, metaclass=ABCMeta):
zhangwenwei's avatar
zhangwenwei committed
6
    """Base class for 3d RoIHeads."""
wuyuefeng's avatar
wuyuefeng committed
7
8
9
10
11
12

    def __init__(self,
                 bbox_head=None,
                 mask_roi_extractor=None,
                 mask_head=None,
                 train_cfg=None,
13
14
15
16
                 test_cfg=None,
                 pretrained=None,
                 init_cfg=None):
        super(Base3DRoIHead, self).__init__(init_cfg=init_cfg)
wuyuefeng's avatar
wuyuefeng committed
17
18
19
20
21
22
23
24
25
26
27
28
29
        self.train_cfg = train_cfg
        self.test_cfg = test_cfg

        if bbox_head is not None:
            self.init_bbox_head(bbox_head)

        if mask_head is not None:
            self.init_mask_head(mask_roi_extractor, mask_head)

        self.init_assigner_sampler()

    @property
    def with_bbox(self):
zhangwenwei's avatar
zhangwenwei committed
30
        """bool: whether the RoIHead has box head"""
wuyuefeng's avatar
wuyuefeng committed
31
32
33
34
        return hasattr(self, 'bbox_head') and self.bbox_head is not None

    @property
    def with_mask(self):
zhangwenwei's avatar
zhangwenwei committed
35
        """bool: whether the RoIHead has mask head"""
wuyuefeng's avatar
wuyuefeng committed
36
37
38
39
        return hasattr(self, 'mask_head') and self.mask_head is not None

    @abstractmethod
    def init_bbox_head(self):
zhangwenwei's avatar
zhangwenwei committed
40
        """Initialize the box head."""
wuyuefeng's avatar
wuyuefeng committed
41
42
43
44
        pass

    @abstractmethod
    def init_mask_head(self):
zhangwenwei's avatar
zhangwenwei committed
45
        """Initialize maek head."""
wuyuefeng's avatar
wuyuefeng committed
46
47
48
49
        pass

    @abstractmethod
    def init_assigner_sampler(self):
zhangwenwei's avatar
zhangwenwei committed
50
        """Initialize assigner and sampler."""
wuyuefeng's avatar
wuyuefeng committed
51
52
53
54
55
        pass

    @abstractmethod
    def forward_train(self,
                      x,
zhangwenwei's avatar
zhangwenwei committed
56
                      img_metas,
wuyuefeng's avatar
wuyuefeng committed
57
58
59
60
61
                      proposal_list,
                      gt_bboxes,
                      gt_labels,
                      gt_bboxes_ignore=None,
                      **kwargs):
zhangwenwei's avatar
zhangwenwei committed
62
        """Forward function during training.
wuyuefeng's avatar
wuyuefeng committed
63
64
65
66
67

        Args:
            x (dict): Contains features from the first stage.
            img_metas (list[dict]): Meta info of each image.
            proposal_list (list[dict]): Proposal information from rpn.
zhangwenwei's avatar
zhangwenwei committed
68
            gt_bboxes (list[:obj:`BaseInstance3DBoxes`]):
wuyuefeng's avatar
wuyuefeng committed
69
70
                GT bboxes of each sample. The bboxes are encapsulated
                by 3D box structures.
71
72
            gt_labels (list[torch.LongTensor]): GT labels of each sample.
            gt_bboxes_ignore (list[torch.Tensor], optional):
zhangwenwei's avatar
zhangwenwei committed
73
                Ground truth boxes to be ignored.
wuyuefeng's avatar
wuyuefeng committed
74
75

        Returns:
wangtai's avatar
wangtai committed
76
            dict[str, torch.Tensor]: Losses from each head.
wuyuefeng's avatar
wuyuefeng committed
77
        """
wuyuefeng's avatar
wuyuefeng committed
78
79
80
81
82
        pass

    def simple_test(self,
                    x,
                    proposal_list,
zhangwenwei's avatar
zhangwenwei committed
83
                    img_metas,
wuyuefeng's avatar
wuyuefeng committed
84
85
86
87
88
89
90
91
92
                    proposals=None,
                    rescale=False,
                    **kwargs):
        """Test without augmentation."""
        pass

    def aug_test(self, x, proposal_list, img_metas, rescale=False, **kwargs):
        """Test with augmentations.

93
94
        If rescale is False, then returned bboxes and masks will fit the scale
        of imgs[0].
wuyuefeng's avatar
wuyuefeng committed
95
96
        """
        pass