def __init__(self, in_channels, channels, **kwargs): super().__init__(**kwargs) self.pool = GlobalAvgPool(keep_dim=True) self.fc = Sequential([ Conv2d(in_channels, channels, 1, act='def'), Conv2d(channels, in_channels, 1, act='sigmoid'), ])
def __init__(self, genotype, depth=110, base_width=24, splits=4, zero_init_residual=True, num_classes=10, stages=(64, 64, 128, 256)): super().__init__() self.stages = stages self.splits = splits block = Bottleneck layers = [(depth - 2) // 9] * 3 genotype = genotype.normal self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.in_channels = self.stages[0] self.layer1 = self._make_layer( block, self.stages[1], layers[0], stride=1, base_width=base_width, splits=splits, zero_init_residual=zero_init_residual, genotype=genotype[0]) self.layer2 = self._make_layer( block, self.stages[2], layers[1], stride=2, base_width=base_width, splits=splits, zero_init_residual=zero_init_residual, genotype=genotype[1]) self.layer3 = self._make_layer( block, self.stages[3], layers[2], stride=2, base_width=base_width, splits=splits, zero_init_residual=zero_init_residual, genotype=genotype[2]) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, block, layers, num_classes=10, stages=(64, 64, 128, 256), **kwargs): super().__init__() self.stages = stages self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.in_channels = self.stages[0] self.layer1 = self._make_layer(block, self.stages[1], layers[0], stride=1, **kwargs) self.layer2 = self._make_layer(block, self.stages[2], layers[1], stride=2, **kwargs) self.layer3 = self._make_layer(block, self.stages[3], layers[2], stride=2, **kwargs) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, depth, block='basic', erase_relu=False, num_classes=10): super().__init__() if block == 'basic': block = BasicBlock layers = [(depth - 2) // 6] * 3 else: block = Bottleneck layers = [(depth - 2) // 9] * 3 self.conv = Conv2d(3, self.stages[0], kernel_size=3) self.layer1 = self._make_layer(block, self.stages[0], self.stages[1], layers[0], stride=1, erase_relu=erase_relu) self.layer2 = self._make_layer(block, self.stages[1], self.stages[2], layers[1], stride=2, erase_relu=erase_relu) self.layer3 = self._make_layer(block, self.stages[2], self.stages[3], layers[2], stride=2, erase_relu=erase_relu) self.avgpool = GlobalAvgPool() self.fc = Linear(self.stages[3], num_classes)
def __init__(self): super().__init__() channels = 4 self.stem = Conv2d(1, channels, kernel_size=3, norm='def', act='def') self.normal1 = make_layer_choice(channels) self.reduce1 = Sequential([ Pool2d(kernel_size=3, stride=2), Conv2d(channels, channels * 2, 1) ]) channels = channels * 2 self.normal2 = make_layer_choice(channels) self.reduce2 = Sequential([ Pool2d(kernel_size=3, stride=2), Conv2d(channels, channels * 2, 1) ]) channels = channels * 2 self.normal3 = make_layer_choice(channels) self.avg_pool = GlobalAvgPool() self.fc = Linear(channels, 10) self.alpha_normal = self.add_weight( name='alpha_normal', shape=(self.normal1.n_choices, ), dtype=self.dtype, initializer=RandomNormal(stddev=0.01), trainable=True) self.tau = self.add_weight(name='tau', shape=(), dtype=self.dtype, initializer=Constant(1.0))
def __init__(self, depth, channels_per_group=(64, 128, 256), cardinality=(8, 8, 8), num_classes=100, stages=(64, 64, 128, 256)): super().__init__() self.stages = stages block = Bottleneck layers = [(depth - 2) // 9] * 3 if isinstance(channels_per_group, int): channels_per_group = [channels_per_group] * 3 if isinstance(cardinality, int): cardinality = [cardinality] * 3 self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.in_channels = self.stages[0] self.layer1 = self._make_layer( block, self.stages[1], layers[0], stride=1, channels_per_group=channels_per_group[0], cardinality=cardinality[0]) self.layer2 = self._make_layer( block, self.stages[2], layers[1], stride=2, channels_per_group=channels_per_group[1], cardinality=cardinality[1]) self.layer3 = self._make_layer( block, self.stages[3], layers[2], stride=2, channels_per_group=channels_per_group[2], cardinality=cardinality[2]) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, depth, cardinality, base_width, reduction=16, num_classes=10): super().__init__() layers = [(depth - 2) // 9] * 3 self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.layer1 = self._make_layer(self.stages[0], self.stages[1], layers[0], 1, cardinality, base_width, reduction) self.layer2 = self._make_layer(self.stages[1], self.stages[2], layers[1], 2, cardinality, base_width, reduction) self.layer3 = self._make_layer(self.stages[2], self.stages[3], layers[2], 2, cardinality, base_width, reduction) self.avgpool = GlobalAvgPool() self.fc = Linear(self.stages[3], num_classes)
def __init__(self, start_channels, widening_fractor, depth, groups, radix, drop_path, num_classes=10): super().__init__() num_layers = [(depth - 2) // 9] * 3 strides = [1, 2, 2] self.add_channel = widening_fractor / sum(num_layers) self.in_channels = start_channels self.channels = start_channels layers = [Conv2d(3, start_channels, kernel_size=3, norm='def')] for i, (n, s) in enumerate(zip(num_layers, strides)): layers.append(self._make_layer(n, groups, stride=s, radix=radix, drop_path=drop_path)) layers.append(Sequential([ Norm(self.in_channels), Act(), ])) self.features = Sequential(layers) assert (start_channels + widening_fractor) * Bottleneck.expansion == self.in_channels self.final_pool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, C, layers, steps=3, stem_multiplier=3, drop_path=0.6, num_classes=10): super().__init__() self._C = C self._steps = steps self._drop_path = drop_path C_curr = stem_multiplier * C self.stem = Sequential([ Conv2d(3, C_curr, 3, bias=False), Norm(3, 'def', affine=True), ]) C_prev, C_curr = C_curr, C self.cells = [] for i in range(layers): if i in [layers // 3, 2 * layers // 3]: C_curr *= 2 cell = BasicBlock(C_prev, C_curr, stride=2) else: cell = Cell(steps, C_prev, C_curr, drop_path) self.cells.append(cell) C_prev = C_curr self.global_pool = GlobalAvgPool() self.fc = Linear(C_prev, num_classes) k = sum(1 + i for i in range(self._steps)) num_ops = len(get_primitives()) self.alphas_normal = self.add_weight( 'alphas_normal', (k, num_ops), initializer=RandomNormal(stddev=1e-2), trainable=True, )
def __init__(self, depth, k, dropout=0, reduction=8, num_classes=10): super().__init__() num_blocks = (depth - 4) // 6 self.conv = Conv2d(3, self.stages[0], kernel_size=3) self.layer1 = self._make_layer(self.stages[0] * 1, self.stages[1] * k, num_blocks, stride=1, dropout=dropout, reduction=reduction) self.layer2 = self._make_layer(self.stages[1] * k, self.stages[2] * k, num_blocks, stride=2, dropout=dropout, reduction=reduction) self.layer3 = self._make_layer(self.stages[2] * k, self.stages[3] * k, num_blocks, stride=2, dropout=dropout, reduction=reduction) self.norm = Norm(self.stages[3] * k) self.act = Act() self.avgpool = GlobalAvgPool() self.fc = Linear(self.stages[3] * k, num_classes)
def __init__(self, genotype, block, layers, base_width=24, splits=4, zero_init_residual=False, num_classes=1000, stages=(64, 64, 128, 256, 512)): super().__init__() self.stages = stages self.splits = splits self.stem = ResNetvdStem(self.stages[0]) self.in_channels = self.stages[0] self.layer1 = self._make_layer( block, self.stages[1], layers[0], stride=1, base_width=base_width, splits=splits, zero_init_residual=zero_init_residual, genotype=genotype) self.layer2 = self._make_layer( block, self.stages[2], layers[1], stride=2, base_width=base_width, splits=splits, zero_init_residual=zero_init_residual, genotype=genotype) self.layer3 = self._make_layer( block, self.stages[3], layers[2], stride=2, base_width=base_width, splits=splits, zero_init_residual=zero_init_residual, genotype=genotype) self.layer4 = self._make_layer( block, self.stages[4], layers[3], stride=2, base_width=base_width, splits=splits, zero_init_residual=zero_init_residual, genotype=genotype) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, block, layers, num_classes=1000, stages=(64, 64, 128, 256, 512), **kwargs): super().__init__() self.stages = stages self.stem = ResNetvdStem(self.stages[0]) self.in_channels = self.stages[0] self.layer1 = self._make_layer(block, self.stages[1], layers[0], stride=1, **kwargs) self.layer2 = self._make_layer(block, self.stages[2], layers[1], stride=2, **kwargs) self.layer3 = self._make_layer(block, self.stages[3], layers[2], stride=2, **kwargs) self.layer4 = self._make_layer(block, self.stages[4], layers[3], stride=2, **kwargs) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, C, layers, auxiliary, drop_path, num_classes, genotype): super().__init__() self._num_layers = layers self._auxiliary = auxiliary self._drop_path = drop_path stem_multiplier = 3 C_curr = stem_multiplier * C self.stem = Conv2d(3, C_curr, 3, norm='def') C_prev_prev, C_prev, C_curr = C_curr, C_curr, C self.cells = [] reduction_prev = False for i in range(layers): if i in [layers // 3, 2 * layers // 3]: C_curr *= 2 reduction = True else: reduction = False cell = Cell(genotype, C_prev_prev, C_prev, C_curr, reduction, reduction_prev, drop_path) reduction_prev = reduction self.cells.append(cell) C_prev_prev, C_prev = C_prev, cell.multiplier * C_curr if i == 2 * layers // 3: C_to_auxiliary = C_prev if auxiliary: self.auxiliary_head = AuxiliaryHeadCIFAR(C_to_auxiliary, num_classes) self.classifier = Sequential([ GlobalAvgPool(), Linear(C_prev, num_classes), ])
def __init__(self, stages_repeats, stages_out_channels, num_classes=1000): super().__init__() if len(stages_repeats) != 3: raise ValueError('expected stages_repeats as list of 3 positive ints') if len(stages_out_channels) != 5: raise ValueError('expected stages_out_channels as list of 5 positive ints') self._stage_out_channels = stages_out_channels in_channels = 3 out_channels = self._stage_out_channels[0] self.stem = Sequential([ Conv2d(in_channels, out_channels, 3, stride=2, norm='def', act='def'), Pool2d(3, stride=2, type='max'), ]) in_channels = out_channels stage_names = ['stage{}'.format(i) for i in [2, 3, 4]] for name, repeats, out_channels in zip( stage_names, stages_repeats, self._stage_out_channels[1:]): seq = [InvertedResidual(in_channels, out_channels, 2)] for i in range(repeats - 1): seq.append(InvertedResidual(out_channels, out_channels, 1)) setattr(self, name, Sequential(seq)) in_channels = out_channels out_channels = self._stage_out_channels[-1] self.final_conv = Conv2d(in_channels, out_channels, kernel_size=1, norm='def', act='def') self.avgpool = GlobalAvgPool() self.fc = Linear(out_channels, num_classes)
def __init__(self, layers=(3, 4, 8, 3), num_classes=1000, channels=(64, 64, 128, 256, 512), strides=(1, 2, 2, 2), dropout=0, **kwargs): super().__init__() self.splits = kwargs.get("scale", 4) block = Bottleneck stem_channels, *channels = channels self.stem = SpaceToDepthStem(stem_channels) c_in = self.stem.out_channels blocks = (block, ) * 4 if not isinstance(block, tuple) else block for i, (block, c, n, s) in enumerate(zip(blocks, channels, layers, strides)): layer = _make_layer(block, c_in, c, n, s, **_get_kwargs(kwargs, i), return_seq=False) c_in = c * block.expansion setattr(self, "layer" + str(i + 1), layer) self.avgpool = GlobalAvgPool() self.dropout = Dropout(dropout) if dropout else None self.fc = Linear(c_in, num_classes) self._initialize_alphas() self.fair_loss_weight = self.add_weight( name="fair_loss_weight", shape=(), dtype=self.dtype, initializer=Constant(1.), trainable=False, ) self.conn_loss_weight = self.add_weight( name="conn_loss_weight", shape=(), dtype=self.dtype, initializer=Constant(1.), trainable=False, ) self.l2_loss_weight = self.add_weight( name="l2_loss_weight", shape=(), dtype=self.dtype, initializer=Constant(1.), trainable=False, )
def __init__(self, in_channels, num_paths, reduction): super().__init__() self.num_paths = num_paths channels = min(max(in_channels // reduction, 32), in_channels) self.pool = GlobalAvgPool(keep_dim=True) self.fc = Sequential([ Conv2d(in_channels, channels, 1, norm='def', act='def'), Conv2d(channels, in_channels * num_paths, 1), ])
def __init__(self, C, layers, steps=4, multiplier=4, stem_multiplier=3, drop_path=0, num_classes=10): super().__init__() self._C = C self._steps = steps self._multiplier = multiplier self._drop_path = drop_path C_curr = stem_multiplier * C self.stem = Sequential([ Conv2d(3, C_curr, 3, bias=False), Norm(C_curr, 'def', affine=True), ]) C_prev_prev, C_prev, C_curr = C_curr, C_curr, C self.cells = [] reduction_prev = False for i in range(layers): if i in [layers // 3, 2 * layers // 3]: C_curr *= 2 reduction = True else: reduction = False cell = Cell(steps, multiplier, C_prev_prev, C_prev, C_curr, reduction, reduction_prev, drop_path) reduction_prev = reduction self.cells.append(cell) C_prev_prev, C_prev = C_prev, multiplier * C_curr self.avg_pool = GlobalAvgPool() self.classifier = Linear(C_prev, num_classes) k = sum(2 + i for i in range(self._steps)) num_ops = len(get_primitives()) self.alphas_normal = self.add_weight( 'alphas_normal', (k, num_ops), initializer=RandomNormal(stddev=1e-2), trainable=True, experimental_autocast=False) self.alphas_reduce = self.add_weight( 'alphas_reduce', (k, num_ops), initializer=RandomNormal(stddev=1e-2), trainable=True, experimental_autocast=False) self.tau = self.add_weight('tau', (), initializer=Constant(1.0), trainable=False, experimental_autocast=False)
def __init__(self, channels=64, r=4): super().__init__() inter_channels = int(channels // r) self.local_att = Sequential([ Conv2d(channels, inter_channels, kernel_size=1, norm='def', act='def'), Conv2d(inter_channels, channels, kernel_size=1, norm='def') ]) self.global_att = Sequential([ GlobalAvgPool(keep_dim=True), Conv2d(channels, inter_channels, kernel_size=1, norm='def', act='def'), Conv2d(inter_channels, channels, kernel_size=1, norm='def') ]) self.local_att2 = Sequential([ Conv2d(channels, inter_channels, kernel_size=1, norm='def', act='def'), Conv2d(inter_channels, channels, kernel_size=1, norm='def') ]) self.global_att2 = Sequential([ GlobalAvgPool(keep_dim=True), Conv2d(channels, inter_channels, kernel_size=1, norm='def', act='def'), Conv2d(inter_channels, channels, kernel_size=1, norm='def') ])
def __init__(self, start_channels, alpha, depth, block='bottleneck', p_shakedrop=0.5, num_classes=10): super().__init__() if block == 'basic': num_layers = [(depth - 2) // 6] * 3 block = BasicBlock elif block == 'bottleneck': num_layers = [(depth - 2) // 9] * 3 block = Bottleneck else: raise ValueError("block must be `basic` or `bottleneck`, got %s" % block) self.num_layers = num_layers strides = [1, 2, 2] add_channel = alpha / sum(num_layers) in_channels = start_channels self.init_block = Conv2d(3, start_channels, kernel_size=3, norm='def') channels = start_channels k = 1 units = [] for n, s in zip(num_layers, strides): for i in range(n): stride = s if i == 0 else 1 channels = channels + add_channel units.append( block(in_channels, rd(channels), stride=stride, p_shakedrop=k / sum(num_layers) * p_shakedrop)) in_channels = rd(channels) * block.expansion k += 1 self.units = units self.post_activ = Sequential([ Norm(in_channels), Act(), ]) assert (start_channels + alpha) * block.expansion == in_channels self.final_pool = GlobalAvgPool() self.fc = Linear(in_channels, num_classes)
def __init__(self, C, num_classes): """assuming input size 8x8""" super().__init__() self.features = Sequential([ Act(), Pool2d(5, stride=3, padding=0, type='avg'), Conv2d(C, 128, 1, norm='def', act='def'), Conv2d(128, 768, 2, norm='def', act='def', padding=0), ]) self.classifier = Sequential([ GlobalAvgPool(), Linear(768, num_classes), ])
def __init__(self, depth, block='basic', dropout=0, drop_path=0, rezero=True, num_classes=10, stages=(64, 64, 128, 256)): super().__init__() self.stages = stages if block == 'basic': block = BasicBlock layers = [(depth - 2) // 6] * 3 else: block = Bottleneck layers = [(depth - 2) // 9] * 3 self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.in_channels = self.stages[0] self.layer1 = self._make_layer(block, self.stages[1], layers[0], stride=1, dropout=dropout, drop_path=drop_path, rezero=rezero) self.layer2 = self._make_layer(block, self.stages[2], layers[1], stride=2, dropout=dropout, drop_path=drop_path, rezero=rezero) self.layer3 = self._make_layer(block, self.stages[3], layers[2], stride=2, dropout=dropout, drop_path=drop_path, rezero=rezero) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, stem_channels, stages, layers, channels_per_group, se_reduction, zero_init_residual=False, num_classes=1000): super().__init__() block = Bottleneck self.stem = SimpleStem(stem_channels) self.in_channels = stem_channels gs = [c // channels_per_group for c in stages] self.stage1 = self._make_layer(block, stages[0], layers[0], stride=2, groups=gs[0], zero_init_residual=zero_init_residual, reduction=se_reduction) self.stage2 = self._make_layer(block, stages[1], layers[1], stride=2, groups=gs[1], zero_init_residual=zero_init_residual, reduction=se_reduction) self.stage3 = self._make_layer(block, stages[2], layers[2], stride=2, groups=gs[2], zero_init_residual=zero_init_residual, reduction=se_reduction) self.stage4 = self._make_layer(block, stages[3], layers[3], stride=2, groups=gs[3], zero_init_residual=zero_init_residual, reduction=se_reduction) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, width_coefficient, depth_coefficient, dropout, drop_connect=0.3, depth_divisor=8, num_classes=1000): super().__init__() round_channels_ = partial(round_channels, width_coefficient=width_coefficient, depth_divisor=depth_divisor) round_repeats_ = partial(round_repeats, depth_coefficient=depth_coefficient) self.stem = Conv2d(3, round_channels_(32), 3, stride=2, padding='SAME', norm='def', act='def') blocks = [] b = 0 n_blocks = float(sum(round_repeats_(args[0]) for args in blocks_args)) for r, k, s, e, i, o, se in blocks_args: in_channels = round_channels_(i) out_channels = round_channels_(o) for j in range(round_repeats_(r)): stride = s if j == 0 else 1 blocks.append( MBConv(in_channels, out_channels, k, stride, e, se, drop_connect * b / n_blocks)) in_channels = out_channels b += 1 self.blocks = Sequential(blocks) self.top = Conv2d(out_channels, round_channels_(1280), 1, norm='def', act='def') self.avgpool = GlobalAvgPool() self.dropout = Dropout(dropout) self.fc = Linear(round_channels_(1280), num_classes)
def __init__(self, in_channels, reduction=None, groups=1, se_channels=None, min_se_channels=32, act='def', **kwargs): super().__init__(**kwargs) channels = se_channels or min( max(in_channels // reduction, min_se_channels), in_channels) if groups != 1: channels = round_channels(channels, groups) self.pool = GlobalAvgPool(keep_dim=True) self.fc = Sequential([ Conv2d(in_channels, channels, 1, groups=groups, act=act), Conv2d(channels, in_channels, 1, groups=groups, act='sigmoid'), ])
def __init__(self, depth, block='basic', erase_relu=False, avd=False, num_classes=10, stages=(16, 16, 32, 64)): super().__init__() self.stages = stages if block == 'basic': block = BasicBlock layers = [(depth - 2) // 6] * 3 else: block = Bottleneck layers = [(depth - 2) // 9] * 3 self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.in_channels = self.stages[0] self.layer1 = self._make_layer(block, self.stages[1], layers[0], stride=1, erase_relu=erase_relu, avd=avd) self.layer2 = self._make_layer(block, self.stages[2], layers[1], stride=2, erase_relu=erase_relu, avd=avd) self.layer3 = self._make_layer(block, self.stages[3], layers[2], stride=2, erase_relu=erase_relu, avd=avd) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, stem_channels=32, channels_per_stage=(128, 256, 512), units_per_stage=(4, 8, 4), final_channels=1024, use_se=True, dropout=0.2, num_classes=10): super().__init__() self.dropout = dropout cs = [stem_channels] + list(channels_per_stage) ns = units_per_stage self.stem = Conv2d(3, stem_channels, 3, norm='def', act='def') self.stage1 = _make_layer(cs[0], cs[1], ns[0], stride=1, use_se=use_se) self.stage2 = _make_layer(cs[1], cs[2], ns[1], stride=2, use_se=use_se) self.stage3 = _make_layer(cs[2], cs[3], ns[2], stride=2, use_se=use_se) self.final_conv = Conv2d(cs[-1], final_channels, 1, norm='def', act='def') self.global_pool = GlobalAvgPool() if dropout: self.dropout = Dropout(dropout) self.classifier = Linear(final_channels, num_classes)
def __init__(self, depth=32, k=4, deep_stem=False, askc_type='DirectAdd', num_classes=10): super().__init__() num_blocks = (depth - 2) // 6 stages = [c * k for c in self.stages] if not deep_stem: self.stem = Conv2d(3, stages[0], kernel_size=3, bias=False) else: stem_channels = stages[0] // 2 self.stem = Sequential([ Conv2d(3, stem_channels, kernel_size=3, norm='def', act='def'), Conv2d(stem_channels, stem_channels, kernel_size=3, norm='def', act='def'), Conv2d(stem_channels, stages[0], kernel_size=3, bias=False) ]) self.layer1 = self._make_layer(stages[0], stages[1], num_blocks, stride=1, askc_type=askc_type) self.layer2 = self._make_layer(stages[1], stages[2], num_blocks, stride=2, askc_type=askc_type) self.layer3 = self._make_layer(stages[2], stages[3], num_blocks, stride=2, askc_type=askc_type) self.norm = Norm(stages[3]) self.act = Act() self.avgpool = GlobalAvgPool() self.fc = Linear(stages[3], num_classes)
def __init__(self, depth, cardinality, base_width, zero_init_residual=True, num_classes=10, stages=(64, 64, 128, 256)): super().__init__() self.stages = stages block = Bottleneck layers = [(depth - 2) // 9] * 3 self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.in_channels = self.stages[0] self.layer1 = self._make_layer(block, self.stages[1], layers[0], stride=1, cardinality=cardinality, base_width=base_width, zero_init_residual=zero_init_residual) self.layer2 = self._make_layer(block, self.stages[2], layers[1], stride=2, cardinality=cardinality, base_width=base_width, zero_init_residual=zero_init_residual) self.layer3 = self._make_layer(block, self.stages[3], layers[2], stride=2, cardinality=cardinality, base_width=base_width, zero_init_residual=zero_init_residual) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes)
def __init__(self, depth=56, base_width=13, splits=4, num_classes=10, stages=(32, 32, 64, 128)): super().__init__() self.stages = stages self.splits = splits block = Bottleneck layers = [(depth - 2) // 9] * 3 self.num_stages = len(layers) self.stem = Conv2d(3, self.stages[0], kernel_size=3, norm='def', act='def') self.in_channels = self.stages[0] self.layer1 = self._make_layer(block, self.stages[1], layers[0], stride=1, base_width=base_width, splits=splits) self.layer2 = self._make_layer(block, self.stages[2], layers[1], stride=2, base_width=base_width, splits=splits) self.layer3 = self._make_layer(block, self.stages[3], layers[2], stride=2, base_width=base_width, splits=splits) self.avgpool = GlobalAvgPool() self.fc = Linear(self.in_channels, num_classes) self._initialize_alphas()
def __init__(self, depth=38, k=4, cardinality=32, bottleneck_width=4, use_se=False, askc_type='DirectAdd', num_classes=10): super().__init__() num_blocks = (depth - 2) // 9 stages = [self.stages[0] * k] + [ c * k * AFFResNeXtBlock.expansion for c in self.stages[1:] ] self.stem = Conv2d(3, stages[0], kernel_size=3, norm='def', act='def') self.layer1 = self._make_layer(stages[0], stages[1], num_blocks, stride=1, cardinality=cardinality, bottleneck_width=bottleneck_width, use_se=use_se, askc_type=askc_type) self.layer2 = self._make_layer(stages[1], stages[2], num_blocks, stride=2, cardinality=cardinality, bottleneck_width=bottleneck_width, use_se=use_se, askc_type=askc_type) self.layer3 = self._make_layer(stages[2], stages[3], num_blocks, stride=2, cardinality=cardinality, bottleneck_width=bottleneck_width, use_se=use_se, askc_type=askc_type) self.avgpool = GlobalAvgPool() self.fc = Linear(stages[3], num_classes)