base_3droi_head.py 2.91 KB
Newer Older
wuyuefeng's avatar
wuyuefeng committed
1
from abc import ABCMeta, abstractmethod
zhangwenwei's avatar
zhangwenwei committed
2
from torch import nn as nn
wuyuefeng's avatar
wuyuefeng committed
3
4
5


class Base3DRoIHead(nn.Module, metaclass=ABCMeta):
zhangwenwei's avatar
zhangwenwei committed
6
    """Base class for 3d RoIHeads."""
wuyuefeng's avatar
wuyuefeng committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

    def __init__(self,
                 bbox_head=None,
                 mask_roi_extractor=None,
                 mask_head=None,
                 train_cfg=None,
                 test_cfg=None):
        super(Base3DRoIHead, self).__init__()
        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
28
        """bool: whether the RoIHead has box head"""
wuyuefeng's avatar
wuyuefeng committed
29
30
31
32
        return hasattr(self, 'bbox_head') and self.bbox_head is not None

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

    @abstractmethod
    def init_weights(self, pretrained):
zhangwenwei's avatar
zhangwenwei committed
38
        """Initialize the module with pre-trained weights."""
wuyuefeng's avatar
wuyuefeng committed
39
40
41
42
        pass

    @abstractmethod
    def init_bbox_head(self):
zhangwenwei's avatar
zhangwenwei committed
43
        """Initialize the box head."""
wuyuefeng's avatar
wuyuefeng committed
44
45
46
47
        pass

    @abstractmethod
    def init_mask_head(self):
zhangwenwei's avatar
zhangwenwei committed
48
        """Initialize maek head."""
wuyuefeng's avatar
wuyuefeng committed
49
50
51
52
        pass

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

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

        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
71
            gt_bboxes (list[:obj:`BaseInstance3DBoxes`]):
wuyuefeng's avatar
wuyuefeng committed
72
73
                GT bboxes of each sample. The bboxes are encapsulated
                by 3D box structures.
74
75
            gt_labels (list[torch.LongTensor]): GT labels of each sample.
            gt_bboxes_ignore (list[torch.Tensor], optional):
zhangwenwei's avatar
zhangwenwei committed
76
                Ground truth boxes to be ignored.
wuyuefeng's avatar
wuyuefeng committed
77
78

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

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

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

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