Пример #1
0
 def make_stage(self, in_channel, out_channel, num, block):
     bottleneck_channels = int(out_channel / 4)
     down_block = PreActBottleNeck(in_channel, bottleneck_channels, 2)
     self.add_block_list(down_block.get_name(), down_block, out_channel)
     for _ in range(num):
         temp_block = block(out_channel, out_channel)
         self.add_block_list(temp_block.get_name(), temp_block, out_channel)
Пример #2
0
    def create_block_list(self):
        self.block_out_channels = []
        self.index = 0

        block1 = ConvBNActivationBlock(in_channels=self.data_channel,
                                       out_channels=self.in_channels[0],
                                       kernel_size=3,
                                       padding=1,
                                       bnName=self.bn_name,
                                       activationName=self.activation_name)
        self.add_block_list(block1.get_name(), block1, self.in_channels[0])

        self.make_stage(self.in_channels[0], self.out_channels[0],
                        self.num_blocks[0], AttentionModule1)
        self.make_stage(self.in_channels[1], self.out_channels[1],
                        self.num_blocks[1], AttentionModule2)
        self.make_stage(self.in_channels[2], self.out_channels[2],
                        self.num_blocks[2], AttentionModule3)

        output_channle = 2048
        bottleneck_channels = int(output_channle / 4)
        block2 = PreActBottleNeck(self.out_channels[2], bottleneck_channels, 2)
        self.add_block_list(block2.get_name(), block2, output_channle)

        block3 = PreActBottleNeck(output_channle, bottleneck_channels, 1)
        self.add_block_list(block3.get_name(), block3, output_channle)

        block4 = PreActBottleNeck(output_channle, bottleneck_channels, 1)
        self.add_block_list(block4.get_name(), block4, output_channle)
    def _make_residual(self, in_channels, out_channels, p):
        layers = []
        bottleneck_channels = int(out_channels / 4)
        for _ in range(p):
            layers.append(PreActBottleNeck(in_channels, bottleneck_channels, 1))

        return nn.Sequential(*layers)
    def __init__(self, in_channels, out_channels, p=1, t=2, r=1,
                 bn_name=NormalizationType.BatchNormalize2d,
                 activation_name=ActivationType.ReLU):
        super().__init__(AttentionNetBlockName.AttentionModule3)

        assert in_channels == out_channels

        self.pre = self._make_residual(in_channels, out_channels, p)
        self.trunk = self._make_residual(in_channels, out_channels, t)
        self.soft_resdown1 = self._make_residual(in_channels, out_channels, r)
        self.soft_resdown2 = self._make_residual(in_channels, out_channels, r)

        self.soft_resup1 = self._make_residual(in_channels, out_channels, r)
        self.soft_resup2 = self._make_residual(in_channels, out_channels, r)

        bottleneck_channels = int(out_channels / 4)
        self.shortcut = PreActBottleNeck(in_channels, bottleneck_channels, 1)

        self.sigmoid = nn.Sequential(
            nn.BatchNorm2d(out_channels),
            nn.ReLU(inplace=True),
            nn.Conv2d(out_channels, out_channels, kernel_size=1),
            nn.BatchNorm2d(out_channels),
            nn.ReLU(inplace=True),
            nn.Conv2d(out_channels, out_channels, kernel_size=1),
            nn.Sigmoid()
        )

        self.last = self._make_residual(in_channels, out_channels, p)
    def __init__(self, in_channels, out_channels, p=1, t=2, r=1,
                 bn_name=NormalizationType.BatchNormalize2d,
                 activation_name=ActivationType.ReLU):
        super().__init__(AttentionNetBlockName.AttentionModule2)
        # """The hyperparameter p denotes the number of preprocessing Residual
        # Units before splitting into trunk branch and mask branch. t denotes
        # the number of Residual Units in trunk branch. r denotes the number of
        # Residual Units between adjacent pooling layer in the mask branch."""
        assert in_channels == out_channels

        self.pre = self._make_residual(in_channels, out_channels, p)
        self.trunk = self._make_residual(in_channels, out_channels, t)
        self.soft_resdown1 = self._make_residual(in_channels, out_channels, r)
        self.soft_resdown2 = self._make_residual(in_channels, out_channels, r)
        self.soft_resdown3 = self._make_residual(in_channels, out_channels, r)

        self.soft_resup1 = self._make_residual(in_channels, out_channels, r)
        self.soft_resup2 = self._make_residual(in_channels, out_channels, r)
        self.soft_resup3 = self._make_residual(in_channels, out_channels, r)

        bottleneck_channels = int(out_channels / 4)
        self.shortcut = PreActBottleNeck(in_channels, bottleneck_channels, 1)

        self.sigmoid = nn.Sequential(
            nn.BatchNorm2d(out_channels),
            nn.ReLU(inplace=True),
            nn.Conv2d(out_channels, out_channels, kernel_size=1),
            nn.BatchNorm2d(out_channels),
            nn.ReLU(inplace=True),
            nn.Conv2d(out_channels, out_channels, kernel_size=1),
            nn.Sigmoid()
        )

        self.last = self._make_residual(in_channels, out_channels, p)