Beispiel #1
0
    def __init__(self):
        super().__init__()
        self.backbone = construct_backbone(cfg.backbone)

        if cfg.freeze_bn:
            self.freeze_bn()

        in_channels = cfg.fpn.num_features  # 256

        self.proto_net, cfg.coef_dim = make_net(in_channels,
                                                cfg.mask_proto_net,
                                                include_last_relu=False)
        '''  
        self.proto_net:
        Sequential((0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (1): ReLU(inplace)
                   (2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (3): ReLU(inplace)
                   (4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (5): ReLU(inplace)
                   (6): InterpolateModule()
                   (7): ReLU(inplace)
                   (8): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (9): ReLU(inplace)
                   (10): Conv2d(256, 32, kernel_size=(1, 1), stride=(1, 1)))
        cfg.coef_dim: 32
        '''

        self.fpn = FPN([512, 1024, 2048])
        self.selected_layers = [0, 1, 2, 3, 4]
        # create a ModuleList to match with the original pre-trained weights (original model state_dict)
        self.prediction_layers = nn.ModuleList()
        self.prediction_layers.append(PredictionModule(in_channels))
        '''  
        self.prediction_layers:
        ModuleList(
          (0): PredictionModule((upfeature): Sequential((0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                                                        (1): ReLU(inplace))
                                (bbox_layer): Conv2d(256, 12, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                                (conf_layer): Conv2d(256, 243, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                                (mask_layer): Conv2d(256, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))))
        '''

        if cfg.train_semantic:  # True
            self.semantic_seg_conv = nn.Conv2d(256,
                                               cfg.num_classes - 1,
                                               kernel_size=1)

        self.anchors = []
        for i, hw in enumerate(cfg.hws):
            self.anchors += make_anchors(hw[1], hw[0], cfg.backbone.scales[i])
        self.anchors = torch.Tensor(self.anchors).view(-1, 4).cuda()
Beispiel #2
0
    def __init__(self, cfg):
        super().__init__()
        self.cfg = cfg
        self.anchors = []
        self.backbone = construct_backbone(cfg.__class__.__name__, (1, 2, 3))
        self.proto_net, coef_dim = make_net(256, mask_proto_net, include_last_relu=False)
        self.fpn = FPN([512, 1024, 2048])
        # create a ModuleList to match with the original pre-trained weights (original model state_dict)
        self.prediction_layers = nn.ModuleList()
        self.prediction_layers.append(PredictionModule(cfg, coef_dim=coef_dim))

        if cfg.mode == 'train':
            self.semantic_seg_conv = nn.Conv2d(256, cfg.num_classes - 1, kernel_size=1)
Beispiel #3
0
    def __init__(self, cfg):
        super().__init__()
        self.cfg = cfg
        self.anchors = []
        self.backbone = construct_backbone(cfg.__class__.__name__, (1, 2, 3))
        self.proto_net, coef_dim = make_net(256,
                                            mask_proto_net,
                                            include_last_relu=False)
        self.fpn = FPN([512, 1024, 2048])
        self.prediction_layers = nn.ModuleList()
        self.prediction_layers.append(PredictionModule(cfg, coef_dim=coef_dim))

        if cfg.mode == 'train':
            ch_out = cfg.num_classes - 1
            self.semantic_seg_conv = nn.Conv2d(256, ch_out, kernel_size=1)
Beispiel #4
0
    def __init__(self, cfg):
        super().__init__()
        self.cfg = cfg
        self.anchors = []
        self.backbone = construct_backbone(cfg.__class__.__name__, (1, 2, 3))

        if cfg.mode == 'train' and cfg.freeze_bn:
            self.freeze_bn()

        self.proto_net, coef_dim = make_net(256,
                                            mask_proto_net,
                                            include_last_relu=False)
        '''  
        self.proto_net:
        Sequential((0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (1): ReLU(inplace)
                   (2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (3): ReLU(inplace)
                   (4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (5): ReLU(inplace)
                   (6): InterpolateModule()
                   (7): ReLU(inplace)
                   (8): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                   (9): ReLU(inplace)
                   (10): Conv2d(256, 32, kernel_size=(1, 1), stride=(1, 1)))
        '''

        self.fpn = FPN([512, 1024, 2048])
        # create a ModuleList to match with the original pre-trained weights (original model state_dict)
        self.prediction_layers = nn.ModuleList()
        self.prediction_layers.append(PredictionModule(cfg, coef_dim=coef_dim))
        '''  
        self.prediction_layers:
        ModuleList(
          (0): PredictionModule((upfeature): Sequential((0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                                                        (1): ReLU(inplace))
                                (bbox_layer): Conv2d(256, 12, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                                (conf_layer): Conv2d(256, 243, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
                                (mask_layer): Conv2d(256, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))))
        '''

        if cfg.mode == 'train' and cfg.train_semantic:  # True
            self.semantic_seg_conv = nn.Conv2d(256,
                                               cfg.num_classes - 1,
                                               kernel_size=1)