Пример #1
0
    def __init__(self,
                 inplanes,
                 planes,
                 stride=1,
                 downsample=None,
                 drop_rate=0.0,
                 drop_block=False,
                 block_size=1):
        super(BasicBlock, self).__init__()
        self.conv1 = conv3x3(inplanes, planes)
        self.bn1 = nn.BatchNorm2d(planes)
        self.relu = nn.LeakyReLU(0.1)
        self.conv2 = conv3x3(planes, planes)
        self.bn2 = nn.BatchNorm2d(planes)
        self.conv3 = conv3x3(planes, planes)
        self.bn3 = nn.BatchNorm2d(planes)
        self.maxpool = nn.MaxPool2d(stride)
        self.downsample = downsample
        self.stride = stride

        self.drop_rate = drop_rate
        self.num_batches_tracked = 0
        self.drop_block = drop_block
        self.block_size = block_size
        self.DropBlock = DropBlock(block_size=self.block_size)
Пример #2
0
    def __init__(self,
                 inplanes,
                 planes,
                 stride=1,
                 downsample=None,
                 drop_rate=0.0,
                 drop_block=False,
                 block_size=1,
                 final_relu=True,
                 film_indim=1,
                 film_alpha=1,
                 film_act=F.leaky_relu,
                 film_normalize=True,
                 dual_BN=True):
        super(BasicBlockFiLM, self).__init__()

        self.conv1 = conv3x3(inplanes, planes)
        self.bn1 = DualBN2d(planes) if dual_BN else nn.BatchNorm2d(planes)
        self.film1 = FiLM_Layer(planes,
                                in_channels=film_indim,
                                alpha=film_alpha,
                                activation=film_act,
                                normalize=film_normalize)
        self.relu = nn.LeakyReLU(0.1)

        self.conv2 = conv3x3(planes, planes)
        self.bn2 = DualBN2d(planes) if dual_BN else nn.BatchNorm2d(planes)
        self.film2 = FiLM_Layer(planes,
                                in_channels=film_indim,
                                alpha=film_alpha,
                                activation=film_act,
                                normalize=film_normalize)

        self.conv3 = conv3x3(planes, planes)
        self.bn3 = DualBN2d(planes) if dual_BN else nn.BatchNorm2d(planes)
        self.film3 = FiLM_Layer(planes,
                                in_channels=film_indim,
                                alpha=film_alpha,
                                activation=film_act,
                                normalize=film_normalize)

        self.maxpool = nn.MaxPool2d(stride)
        self.downsample = downsample
        if self.downsample:
            self.conv_ds = nn.Conv2d(inplanes,
                                     planes * self.expansion,
                                     kernel_size=1,
                                     stride=1,
                                     bias=False)
            if dual_BN:
                self.bn_ds = DualBN2d(planes * self.expansion)
            else:
                self.bn_ds = nn.BatchNorm2d(planes * self.expansion)
            self.film_ds = FiLM_Layer(planes * self.expansion,
                                      in_channels=film_indim,
                                      alpha=film_alpha,
                                      activation=film_act,
                                      normalize=film_normalize)

        self.stride = stride
        self.drop_rate = drop_rate
        self.num_batches_tracked = 0
        self.drop_block = drop_block
        self.block_size = block_size
        self.dual_BN = dual_BN
        self.DropBlock = DropBlock(block_size=self.block_size)
        self.final_relu = final_relu