def __init__(self, in_channels, num_blocks, cardinality, group_with, stride=2): super(Stem, self).__init__() self.c0 = in_channels // 2 self.c1 = in_channels - in_channels // 2 self.hidden_channels = cardinality * group_with self.out_channels = self.hidden_channels * 2 self.trans_part0 = nn.Sequential(BN_Conv2d_Leaky(self.c0, self.hidden_channels, 1, 1, 0), nn.AvgPool2d(stride)) self.block = self.__make_block(num_blocks, self.c1, cardinality, group_with, stride) self.trans_part1 = BN_Conv2d_Leaky(self.hidden_channels, self.hidden_channels, 1, 1, 0) self.trans = BN_Conv2d_Leaky(self.out_channels, self.out_channels, 1, 1, 0)
def __init__(self, num_blocks, cadinality, group_width, num_classes): super(CSP_ResNeXt, self).__init__() self.conv0 = BN_Conv2d_Leaky(3, 64, 7, 2, 3) self.pool1 = nn.MaxPool2d(3, 2, 1) self.conv1 = BN_Conv2d_Leaky(64, 128, 1, 1, 0) self.stem0 = Stem(cadinality * group_width * 2, num_blocks[0], cadinality, group_width, stride=1) self.stem1 = Stem(cadinality * group_width * 4, num_blocks[1], cadinality, group_width * 2) self.stem2 = Stem(cadinality * group_width * 8, num_blocks[2], cadinality, group_width * 4) self.stem3 = Stem(cadinality * group_width * 16, num_blocks[3], cadinality, group_width * 8) self.global_pool = nn.AdaptiveAvgPool2d((1, 1)) self.fc = nn.Linear(cadinality * group_width * 16, num_classes)
def __init__(self, in_channels, cardinality, group_width, stride=1): super(ResidualBlock, self).__init__() self.out_channels = cardinality * group_width self.conv1 = BN_Conv2d_Leaky(in_channels, self.out_channels, 1, 1, 0) self.conv2 = BN_Conv2d_Leaky(self.out_channels, self.out_channels, 3, stride, 1, groups=cardinality) self.conv3 = nn.Conv2d(self.out_channels, self.out_channels, 1, 1, 0) self.bn = nn.BatchNorm2d(self.out_channels) # make shortcut layers = [] if in_channels != self.out_channels: layers.append(nn.Conv2d(in_channels, self.out_channels, 1, 1, 0)) layers.append(nn.BatchNorm2d(self.out_channels)) if stride != 1: layers.append(nn.AvgPool2d(stride)) self.shortcut = nn.Sequential(*layers)
def __init__(self, channels, is_se=False, inner_channels=None): super(Dark_block, self).__init__() self.is_se = is_se if inner_channels is None: inner_channels = channels // 2 self.conv1 = BN_Conv2d_Leaky(channels, inner_channels, 1, 1, 0) self.conv2 = nn.Conv2d(inner_channels, channels, 3, 1, 1) self.bn = nn.BatchNorm2d(channels) if self.is_se: self.se = SE(channels, 16)