base_3droi_head.py 2.57 KB
Newer Older
wuyuefeng's avatar
wuyuefeng committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from abc import ABCMeta, abstractmethod

import torch.nn as nn


class Base3DRoIHead(nn.Module, metaclass=ABCMeta):
    """Base class for 3d RoIHeads"""

    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):
        return hasattr(self, 'bbox_head') and self.bbox_head is not None

    @property
    def with_mask(self):
        return hasattr(self, 'mask_head') and self.mask_head is not None

    @abstractmethod
    def init_weights(self, pretrained):
        pass

    @abstractmethod
    def init_bbox_head(self):
        pass

    @abstractmethod
    def init_mask_head(self):
        pass

    @abstractmethod
    def init_assigner_sampler(self):
        pass

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

        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
66
            gt_bboxes (list[:obj:`BaseInstance3DBoxes`]):
wuyuefeng's avatar
wuyuefeng committed
67
68
69
70
71
72
73
74
                GT bboxes of each sample. The bboxes are encapsulated
                by 3D box structures.
            gt_labels (list[LongTensor]): GT labels of each sample.
            gt_bboxes_ignore (list[Tensor], optional): Specify which bounding.

        Returns:
            dict: losses from each head.
        """
wuyuefeng's avatar
wuyuefeng committed
75
76
77
78
79
        pass

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

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

        If rescale is False, then returned bboxes and masks will fit the scale
        of imgs[0].
        """
        pass