def _make_layer(self, block, channels, blocks, stride=1, **kwargs): layers = [block(self.in_channels, channels, stride=stride, **kwargs)] self.in_channels = channels * block.expansion for i in range(1, blocks): layers.append(block(self.in_channels, channels, stride=1, **kwargs)) return Sequential(layers)
def __init__(self, in_channels, channels, stride, group_channels, cardinality, start_block=False, end_block=False, exclude_bn0=False): super().__init__() out_channels = channels * self.expansion width = group_channels * cardinality if not start_block and not exclude_bn0: self.bn0 = Norm(in_channels) if not start_block: self.act0 = Act() self.conv1 = Conv2d(in_channels, width, kernel_size=1) self.bn1 = Norm(width) self.act1 = Act() self.conv2 = Conv2d(width, width, kernel_size=3, stride=stride, groups=cardinality, norm='def', act='def') self.conv3 = Conv2d(width, out_channels, kernel_size=1) if start_block: self.bn3 = Norm(out_channels) if end_block: self.bn3 = Norm(out_channels) self.act3 = Act() if stride != 1 or in_channels != out_channels: shortcut = [] if stride != 1: shortcut.append(Pool2d(2, 2, type='avg')) shortcut.append( Conv2d(in_channels, out_channels, kernel_size=1, norm='def')) self.shortcut = Sequential(shortcut) else: self.shortcut = Identity() self.start_block = start_block self.end_block = end_block self.exclude_bn0 = exclude_bn0
def __init__(self, in_channels, channels, stride, erase_relu): super().__init__() out_channels = channels * self.expansion self.conv1 = Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, norm='def', act='def') self.conv2 = Conv2d(out_channels, out_channels, kernel_size=3, norm='def') if stride != 1 or in_channels != out_channels: shortcut = [] if stride != 1: shortcut.append(Pool2d(2, 2, type='avg')) shortcut.append( Conv2d(in_channels, out_channels, kernel_size=1, norm='def')) self.shortcut = Sequential(shortcut) else: self.shortcut = Identity() self.act = Act() if not erase_relu else Identity()
def _make_layer(self, block, channels, blocks, stride, **kwargs): layers = [block(self.in_channels, channels, stride=stride, start_block=True, **kwargs)] self.in_channels = channels * block.expansion for i in range(1, blocks): layers.append(block(self.in_channels, channels, stride=1, exclude_bn0=i == 1, end_block=i == blocks - 1, **kwargs)) return Sequential(layers)
def __init__(self, in_channels, channels, stride, dropout, drop_path, start_block=False, end_block=False, exclude_bn0=False): super().__init__() # For torch.jit.script self.bn0 = Identity() self.act0 = Identity() self.act2 = Identity() self.bn2 = Identity() out_channels = channels * self.expansion if not start_block and not exclude_bn0: self.bn0 = Norm(in_channels) if not start_block: self.act0 = Act() self.conv1 = Conv2d(in_channels, out_channels, kernel_size=3, stride=stride) self.bn1 = Norm(out_channels) self.act1 = Act() self.dropout = Dropout(dropout) if dropout else Identity() self.conv2 = Conv2d(out_channels, out_channels, kernel_size=3) if start_block: self.bn2 = Norm(out_channels) self.drop_path = DropPath(drop_path) if drop_path else Identity() if end_block: self.bn2 = Norm(out_channels) self.act2 = Act() if stride != 1 or in_channels != out_channels: shortcut = [] if stride != 1: shortcut.append(Pool2d(2, 2, type='avg')) shortcut.append( Conv2d(in_channels, out_channels, kernel_size=1, norm='def')) self.shortcut = Sequential(shortcut) else: self.shortcut = Identity() self.start_block = start_block self.end_block = end_block self.exclude_bn0 = exclude_bn0