code
stringlengths
17
6.64M
class Mlp(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0): super().__init__() out_features = (out_features or in_features) hidden_features = (hidden_features or in_features) self.fc1 = nn.Linear(in_features, hidden_...
class Attention(nn.Module): def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0, sr_ratio=1): super().__init__() assert ((dim % num_heads) == 0), f'dim {dim} should be divided by num_heads {num_heads}.' self.dim = dim self.num_heads = n...
class Block(nn.Module): def __init__(self, dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=nn.GELU, norm_layer=nn.LayerNorm, sr_ratio=1): super().__init__() self.norm1 = norm_layer(dim) self.attn = Attention(dim, num_heads=nu...
class OverlapPatchEmbed(nn.Module): ' Image to Patch Embedding\n ' def __init__(self, img_size=224, patch_size=7, stride=4, in_chans=3, embed_dim=768): super().__init__() img_size = to_2tuple(img_size) patch_size = to_2tuple(patch_size) self.img_size = img_size self...
class MixVisionTransformer(nn.Module): def __init__(self, img_size=224, patch_size=16, in_chans=3, num_classes=1000, embed_dims=[64, 128, 256, 512], num_heads=[1, 2, 4, 8], mlp_ratios=[4, 4, 4, 4], qkv_bias=False, qk_scale=None, drop_rate=0.0, attn_drop_rate=0.0, drop_path_rate=0.0, norm_layer=nn.LayerNorm, dept...
class DWConv(nn.Module): def __init__(self, dim=768): super(DWConv, self).__init__() self.dwconv = nn.Conv2d(dim, dim, 3, 1, 1, bias=True, groups=dim) def forward(self, x, H, W): (B, N, C) = x.shape x = x.transpose(1, 2).view(B, C, H, W) x = self.dwconv(x) x =...
class mit_b0(MixVisionTransformer): def __init__(self, stride=None, **kwargs): super(mit_b0, self).__init__(patch_size=4, embed_dims=[32, 64, 160, 256], num_heads=[1, 2, 5, 8], mlp_ratios=[4, 4, 4, 4], qkv_bias=True, norm_layer=partial(nn.LayerNorm, eps=1e-06), depths=[2, 2, 2, 2], sr_ratios=[8, 4, 2, 1]...
class mit_b1(MixVisionTransformer): def __init__(self, stride=None, **kwargs): super(mit_b1, self).__init__(patch_size=4, embed_dims=[64, 128, 320, 512], num_heads=[1, 2, 5, 8], mlp_ratios=[4, 4, 4, 4], qkv_bias=True, norm_layer=partial(nn.LayerNorm, eps=1e-06), depths=[2, 2, 2, 2], sr_ratios=[8, 4, 2, 1...
class mit_b2(MixVisionTransformer): def __init__(self, stride=None, **kwargs): super(mit_b2, self).__init__(patch_size=4, embed_dims=[64, 128, 320, 512], num_heads=[1, 2, 5, 8], mlp_ratios=[4, 4, 4, 4], qkv_bias=True, norm_layer=partial(nn.LayerNorm, eps=1e-06), depths=[3, 4, 6, 3], sr_ratios=[8, 4, 2, 1...
class mit_b3(MixVisionTransformer): def __init__(self, stride=None, **kwargs): super(mit_b3, self).__init__(patch_size=4, embed_dims=[64, 128, 320, 512], num_heads=[1, 2, 5, 8], mlp_ratios=[4, 4, 4, 4], qkv_bias=True, norm_layer=partial(nn.LayerNorm, eps=1e-06), depths=[3, 4, 18, 3], sr_ratios=[8, 4, 2, ...
class mit_b4(MixVisionTransformer): def __init__(self, stride=None, **kwargs): super(mit_b4, self).__init__(patch_size=4, embed_dims=[64, 128, 320, 512], num_heads=[1, 2, 5, 8], mlp_ratios=[4, 4, 4, 4], qkv_bias=True, norm_layer=partial(nn.LayerNorm, eps=1e-06), depths=[3, 8, 27, 3], sr_ratios=[8, 4, 2, ...
class mit_b5(MixVisionTransformer): def __init__(self, stride=None, **kwargs): super(mit_b5, self).__init__(patch_size=4, embed_dims=[64, 128, 320, 512], num_heads=[1, 2, 5, 8], mlp_ratios=[4, 4, 4, 4], qkv_bias=True, norm_layer=partial(nn.LayerNorm, eps=1e-06), depths=[3, 6, 40, 3], sr_ratios=[8, 4, 2, ...
class WeTr(nn.Module): def __init__(self, backbone, num_classes=None, embedding_dim=256, stride=None, pretrained=None, pooling=None): super().__init__() self.num_classes = num_classes self.embedding_dim = embedding_dim self.feature_strides = [4, 8, 16, 32] self.stride = st...
class MLP(nn.Module): '\n Linear Embedding\n ' def __init__(self, input_dim=2048, embed_dim=768): super().__init__() self.proj = nn.Linear(input_dim, embed_dim) def forward(self, x): x = x.flatten(2).transpose(1, 2) x = self.proj(x) return x
class SegFormerHead(nn.Module): '\n SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers\n ' def __init__(self, feature_strides=None, in_channels=128, embedding_dim=256, num_classes=20, **kwargs): super(SegFormerHead, self).__init__() self.in_channels = in_...
class Bottleneck(nn.Module): def __init__(self, in_planes, growth_rate): super(Bottleneck, self).__init__() self.bn1 = nn.BatchNorm2d(in_planes) self.conv1 = nn.Conv2d(in_planes, (4 * growth_rate), kernel_size=1, bias=False) self.bn2 = nn.BatchNorm2d((4 * growth_rate)) sel...
class Transition(nn.Module): def __init__(self, in_planes, out_planes): super(Transition, self).__init__() self.bn = nn.BatchNorm2d(in_planes) self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=1, bias=False) def forward(self, x): out = self.conv(F.relu(self.bn(x))) ...
class DenseNet(nn.Module): def __init__(self, block, nblocks, growth_rate=12, reduction=0.5, num_classes=10): super(DenseNet, self).__init__() self.growth_rate = growth_rate num_planes = (2 * growth_rate) self.conv1 = nn.Conv2d(3, num_planes, kernel_size=3, padding=1, bias=False) ...
def DenseNet121(): return DenseNet(Bottleneck, [6, 12, 24, 16], growth_rate=32)
def DenseNet169(): return DenseNet(Bottleneck, [6, 12, 32, 32], growth_rate=32)
def DenseNet201(): return DenseNet(Bottleneck, [6, 12, 48, 32], growth_rate=32)
def DenseNet161(): return DenseNet(Bottleneck, [6, 12, 36, 24], growth_rate=48)
def densenet_cifar(): return DenseNet(Bottleneck, [6, 12, 24, 16], growth_rate=12)
def test(): net = densenet_cifar() x = torch.randn(1, 3, 32, 32) y = net(x) print(y)
class BasicBlock(nn.Module): expansion = 1 def __init__(self, in_planes, planes, stride=1): super(BasicBlock, self).__init__() self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2...
class Root(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=1): super(Root, self).__init__() self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=((kernel_size - 1) // 2), bias=False) self.bn = nn.BatchNorm2d(out_channels) def forward(s...
class Tree(nn.Module): def __init__(self, block, in_channels, out_channels, level=1, stride=1): super(Tree, self).__init__() self.level = level if (level == 1): self.root = Root((2 * out_channels), out_channels) self.left_node = block(in_channels, out_channels, str...
class DLA(nn.Module): def __init__(self, block=BasicBlock, num_classes=10): super(DLA, self).__init__() self.base = nn.Sequential(nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1, bias=False), nn.BatchNorm2d(16), nn.ReLU(True)) self.layer1 = nn.Sequential(nn.Conv2d(16, 16, kernel_size=...
def test(): net = DLA() print(net) x = torch.randn(1, 3, 32, 32) y = net(x) print(y.size())
class BasicBlock(nn.Module): expansion = 1 def __init__(self, in_planes, planes, stride=1): super(BasicBlock, self).__init__() self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2...
class Root(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=1): super(Root, self).__init__() self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=((kernel_size - 1) // 2), bias=False) self.bn = nn.BatchNorm2d(out_channels) def forward(s...
class Tree(nn.Module): def __init__(self, block, in_channels, out_channels, level=1, stride=1): super(Tree, self).__init__() self.root = Root((2 * out_channels), out_channels) if (level == 1): self.left_tree = block(in_channels, out_channels, stride=stride) self.ri...
class SimpleDLA(nn.Module): def __init__(self, block=BasicBlock, num_classes=10): super(SimpleDLA, self).__init__() self.base = nn.Sequential(nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1, bias=False), nn.BatchNorm2d(16), nn.ReLU(True)) self.layer1 = nn.Sequential(nn.Conv2d(16, 16, ...
def test(): net = SimpleDLA() print(net) x = torch.randn(1, 3, 32, 32) y = net(x) print(y.size())
def swish(x): return (x * x.sigmoid())
def drop_connect(x, drop_ratio): keep_ratio = (1.0 - drop_ratio) mask = torch.empty([x.shape[0], 1, 1, 1], dtype=x.dtype, device=x.device) mask.bernoulli_(keep_ratio) x.div_(keep_ratio) x.mul_(mask) return x
class SE(nn.Module): 'Squeeze-and-Excitation block with Swish.' def __init__(self, in_channels, se_channels): super(SE, self).__init__() self.se1 = nn.Conv2d(in_channels, se_channels, kernel_size=1, bias=True) self.se2 = nn.Conv2d(se_channels, in_channels, kernel_size=1, bias=True) ...
class Block(nn.Module): 'expansion + depthwise + pointwise + squeeze-excitation' def __init__(self, in_channels, out_channels, kernel_size, stride, expand_ratio=1, se_ratio=0.0, drop_rate=0.0): super(Block, self).__init__() self.stride = stride self.drop_rate = drop_rate self....
class EfficientNet(nn.Module): def __init__(self, cfg, num_classes=1000): super(EfficientNet, self).__init__() self.cfg = cfg self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(32) self.layers = self._make_layers(in_chan...
def EfficientNetB0(): cfg = {'num_blocks': [1, 2, 2, 3, 3, 4, 1], 'expansion': [1, 6, 6, 6, 6, 6, 6], 'out_channels': [16, 24, 40, 80, 112, 192, 320], 'kernel_size': [3, 3, 5, 3, 5, 5, 3], 'stride': [1, 2, 2, 2, 1, 2, 1], 'dropout_rate': 0.2, 'drop_connect_rate': 0.2} return EfficientNet(cfg)
def test(): net = EfficientNetB0() x = torch.randn(2, 3, 32, 32) y = net(x) print(y.shape)
class Inception(nn.Module): def __init__(self, in_planes, n1x1, n3x3red, n3x3, n5x5red, n5x5, pool_planes): super(Inception, self).__init__() self.b1 = nn.Sequential(nn.Conv2d(in_planes, n1x1, kernel_size=1), nn.BatchNorm2d(n1x1), nn.ReLU(True)) self.b2 = nn.Sequential(nn.Conv2d(in_planes...
class GoogLeNet(nn.Module): def __init__(self): super(GoogLeNet, self).__init__() self.pre_layers = nn.Sequential(nn.Conv2d(3, 192, kernel_size=3, padding=1), nn.BatchNorm2d(192), nn.ReLU(True)) self.a3 = Inception(192, 64, 96, 128, 16, 32, 32) self.b3 = Inception(256, 128, 128, 1...
def test(): net = GoogLeNet() x = torch.randn(1, 3, 32, 32) y = net(x) print(y.size())
class LeNet(nn.Module): def __init__(self): super(LeNet, self).__init__() self.conv1 = nn.Conv2d(3, 6, 5) self.conv2 = nn.Conv2d(6, 16, 5) self.fc1 = nn.Linear(((16 * 5) * 5), 120) self.fc2 = nn.Linear(120, 84) self.fc3 = nn.Linear(84, 10) def forward(self, x)...
class Block(nn.Module): 'Depthwise conv + Pointwise conv' def __init__(self, in_planes, out_planes, stride=1): super(Block, self).__init__() self.conv1 = nn.Conv2d(in_planes, in_planes, kernel_size=3, stride=stride, padding=1, groups=in_planes, bias=False) self.bn1 = nn.BatchNorm2d(in...
class MobileNet(nn.Module): cfg = [64, (128, 2), 128, (256, 2), 256, (512, 2), 512, 512, 512, 512, 512, (1024, 2), 1024] def __init__(self, num_classes=10): super(MobileNet, self).__init__() self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1, bias=False) self.bn1 = nn.Ba...
def test(): net = MobileNet() x = torch.randn(1, 3, 32, 32) y = net(x) print(y.size())
class Block(nn.Module): 'expand + depthwise + pointwise' def __init__(self, in_planes, out_planes, expansion, stride): super(Block, self).__init__() self.stride = stride planes = (expansion * in_planes) self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, stride=1, padding...
class MobileNetV2(nn.Module): cfg = [(1, 16, 1, 1), (6, 24, 2, 1), (6, 32, 3, 2), (6, 64, 4, 2), (6, 96, 3, 1), (6, 160, 3, 2), (6, 320, 1, 1)] def __init__(self, num_classes=10): super(MobileNetV2, self).__init__() self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1, bias=False)...
def test(): net = MobileNetV2() x = torch.randn(2, 3, 32, 32) y = net(x) print(y.size())
class SepConv(nn.Module): 'Separable Convolution.' def __init__(self, in_planes, out_planes, kernel_size, stride): super(SepConv, self).__init__() self.conv1 = nn.Conv2d(in_planes, out_planes, kernel_size, stride, padding=((kernel_size - 1) // 2), bias=False, groups=in_planes) self.bn...
class CellA(nn.Module): def __init__(self, in_planes, out_planes, stride=1): super(CellA, self).__init__() self.stride = stride self.sep_conv1 = SepConv(in_planes, out_planes, kernel_size=7, stride=stride) if (stride == 2): self.conv1 = nn.Conv2d(in_planes, out_planes,...
class CellB(nn.Module): def __init__(self, in_planes, out_planes, stride=1): super(CellB, self).__init__() self.stride = stride self.sep_conv1 = SepConv(in_planes, out_planes, kernel_size=7, stride=stride) self.sep_conv2 = SepConv(in_planes, out_planes, kernel_size=3, stride=strid...
class PNASNet(nn.Module): def __init__(self, cell_type, num_cells, num_planes): super(PNASNet, self).__init__() self.in_planes = num_planes self.cell_type = cell_type self.conv1 = nn.Conv2d(3, num_planes, kernel_size=3, stride=1, padding=1, bias=False) self.bn1 = nn.BatchN...
def PNASNetA(): return PNASNet(CellA, num_cells=6, num_planes=44)
def PNASNetB(): return PNASNet(CellB, num_cells=6, num_planes=32)
def test(): net = PNASNetB() x = torch.randn(1, 3, 32, 32) y = net(x) print(y)
class PreActBlock(nn.Module): 'Pre-activation version of the BasicBlock.' expansion = 1 def __init__(self, in_planes, planes, stride=1): super(PreActBlock, self).__init__() self.bn1 = nn.BatchNorm2d(in_planes) self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride,...
class PreActBottleneck(nn.Module): 'Pre-activation version of the original Bottleneck module.' expansion = 4 def __init__(self, in_planes, planes, stride=1): super(PreActBottleneck, self).__init__() self.bn1 = nn.BatchNorm2d(in_planes) self.conv1 = nn.Conv2d(in_planes, planes, ker...
class PreActResNet(nn.Module): def __init__(self, block, num_blocks, num_classes=10): super(PreActResNet, self).__init__() self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False) self.layer1 = self._make_layer(block, 64, num_blocks[0], str...
def PreActResNet18(): return PreActResNet(PreActBlock, [2, 2, 2, 2])
def PreActResNet34(): return PreActResNet(PreActBlock, [3, 4, 6, 3])
def PreActResNet50(): return PreActResNet(PreActBottleneck, [3, 4, 6, 3])
def PreActResNet101(): return PreActResNet(PreActBottleneck, [3, 4, 23, 3])
def PreActResNet152(): return PreActResNet(PreActBottleneck, [3, 8, 36, 3])
def test(): net = PreActResNet18() y = net(torch.randn(1, 3, 32, 32)) print(y.size())
class SE(nn.Module): 'Squeeze-and-Excitation block.' def __init__(self, in_planes, se_planes): super(SE, self).__init__() self.se1 = nn.Conv2d(in_planes, se_planes, kernel_size=1, bias=True) self.se2 = nn.Conv2d(se_planes, in_planes, kernel_size=1, bias=True) def forward(self, x)...
class Block(nn.Module): def __init__(self, w_in, w_out, stride, group_width, bottleneck_ratio, se_ratio): super(Block, self).__init__() w_b = int(round((w_out * bottleneck_ratio))) self.conv1 = nn.Conv2d(w_in, w_b, kernel_size=1, bias=False) self.bn1 = nn.BatchNorm2d(w_b) ...
class RegNet(nn.Module): def __init__(self, cfg, num_classes=10): super(RegNet, self).__init__() self.cfg = cfg self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(64) self.layer1 = self._make_...
def RegNetX_200MF(): cfg = {'depths': [1, 1, 4, 7], 'widths': [24, 56, 152, 368], 'strides': [1, 1, 2, 2], 'group_width': 8, 'bottleneck_ratio': 1, 'se_ratio': 0} return RegNet(cfg)
def RegNetX_400MF(): cfg = {'depths': [1, 2, 7, 12], 'widths': [32, 64, 160, 384], 'strides': [1, 1, 2, 2], 'group_width': 16, 'bottleneck_ratio': 1, 'se_ratio': 0} return RegNet(cfg)
def RegNetY_400MF(): cfg = {'depths': [1, 2, 7, 12], 'widths': [32, 64, 160, 384], 'strides': [1, 1, 2, 2], 'group_width': 16, 'bottleneck_ratio': 1, 'se_ratio': 0.25} return RegNet(cfg)
def test(): net = RegNetX_200MF() print(net) x = torch.randn(2, 3, 32, 32) y = net(x) print(y.shape)
class BasicBlock(nn.Module): expansion = 1 def __init__(self, in_planes, planes, stride=1): super(BasicBlock, self).__init__() self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2...
class Bottleneck(nn.Module): expansion = 4 def __init__(self, in_planes, planes, stride=1): super(Bottleneck, self).__init__() self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, bias=False) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2d(planes, planes, kernel_s...
class ResNet(nn.Module): def __init__(self, block, num_blocks, num_classes=10): super(ResNet, self).__init__() self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(64) self.layer1 = self._make_layer(blo...
def ResNet18(): return ResNet(BasicBlock, [2, 2, 2, 2])
def ResNet18_11(): return ResNet(BasicBlock, [2, 2, 2, 2], num_classes=11)
def ResNet18_201(): return ResNet(BasicBlock, [2, 2, 2, 2], num_classes=201)
def ResNet34(): return ResNet(BasicBlock, [3, 4, 6, 3])
def ResNet50(): return ResNet(Bottleneck, [3, 4, 6, 3])
def ResNet101(): return ResNet(Bottleneck, [3, 4, 23, 3])
def ResNet152(): return ResNet(Bottleneck, [3, 8, 36, 3])
def test(): net = ResNet18() y = net(torch.randn(1, 3, 32, 32)) print(y.size())
class Block(nn.Module): 'Grouped convolution block.' expansion = 2 def __init__(self, in_planes, cardinality=32, bottleneck_width=4, stride=1): super(Block, self).__init__() group_width = (cardinality * bottleneck_width) self.conv1 = nn.Conv2d(in_planes, group_width, kernel_size=1...
class ResNeXt(nn.Module): def __init__(self, num_blocks, cardinality, bottleneck_width, num_classes=10): super(ResNeXt, self).__init__() self.cardinality = cardinality self.bottleneck_width = bottleneck_width self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=1,...
def ResNeXt29_2x64d(): return ResNeXt(num_blocks=[3, 3, 3], cardinality=2, bottleneck_width=64)
def ResNeXt29_4x64d(): return ResNeXt(num_blocks=[3, 3, 3], cardinality=4, bottleneck_width=64)
def ResNeXt29_8x64d(): return ResNeXt(num_blocks=[3, 3, 3], cardinality=8, bottleneck_width=64)
def ResNeXt29_32x4d(): return ResNeXt(num_blocks=[3, 3, 3], cardinality=32, bottleneck_width=4)
def test_resnext(): net = ResNeXt29_2x64d() x = torch.randn(1, 3, 32, 32) y = net(x) print(y.size())
class BasicBlock(nn.Module): def __init__(self, in_planes, planes, stride=1): super(BasicBlock, self).__init__() self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2d(planes, planes, ...
class PreActBlock(nn.Module): def __init__(self, in_planes, planes, stride=1): super(PreActBlock, self).__init__() self.bn1 = nn.BatchNorm2d(in_planes) self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.bn2 = nn.BatchNorm2d(planes) ...
class SENet(nn.Module): def __init__(self, block, num_blocks, num_classes=10): super(SENet, self).__init__() self.in_planes = 64 self.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(64) self.layer1 = self._make_layer(block...
def SENet18(): return SENet(PreActBlock, [2, 2, 2, 2])
def test(): net = SENet18() y = net(torch.randn(1, 3, 32, 32)) print(y.size())
class ShuffleBlock(nn.Module): def __init__(self, groups): super(ShuffleBlock, self).__init__() self.groups = groups def forward(self, x): 'Channel shuffle: [N,C,H,W] -> [N,g,C/g,H,W] -> [N,C/g,g,H,w] -> [N,C,H,W]' (N, C, H, W) = x.size() g = self.groups retur...
class Bottleneck(nn.Module): def __init__(self, in_planes, out_planes, stride, groups): super(Bottleneck, self).__init__() self.stride = stride mid_planes = (out_planes / 4) g = (1 if (in_planes == 24) else groups) self.conv1 = nn.Conv2d(in_planes, mid_planes, kernel_size=...
class ShuffleNet(nn.Module): def __init__(self, cfg): super(ShuffleNet, self).__init__() out_planes = cfg['out_planes'] num_blocks = cfg['num_blocks'] groups = cfg['groups'] self.conv1 = nn.Conv2d(3, 24, kernel_size=1, bias=False) self.bn1 = nn.BatchNorm2d(24) ...