def __init__(self, multiplier=1.0, classes=1000, **kwargs): super(MobileNet, self).__init__(**kwargs) self.features = list() _add_conv(self.features, 3, channels=int(32 * multiplier), kernel=3, pad=1, stride=2) dw_channels = [int(x * multiplier) for x in [32, 64] + [128] * 2 + [256] * 2 + [512] * 6 + [1024]] channels = [int(x * multiplier) for x in [64] + [128] * 2 + [256] * 2 + [512] * 6 + [1024] * 2] strides = [1, 2] * 3 + [1] * 5 + [2, 1] in_channels = int(32 * multiplier) for dwc, c, s in zip(dw_channels, channels, strides): _add_conv_dw(self.features, in_channels, dw_channels=dwc, channels=c, stride=s) in_channels = c self.features = nn.Sequential(*self.features) self.output = nn.Linear(channels[-1], classes)
def __init__(self, multiplier=1.0, classes=1000, **kwargs): super(MobileNetV2, self).__init__(**kwargs) self.features = list() _add_conv(self.features, 3, int(32 * multiplier), kernel=3, stride=2, pad=1, relu6=True) in_channels_group = [int(x * multiplier) for x in [32] + [16] + [24] * 2 + [32] * 3 + [64] * 4 + [96] * 3 + [160] * 3] channels_group = [int(x * multiplier) for x in [16] + [24] * 2 + [32] * 3 + [64] * 4 + [96] * 3 + [160] * 3 + [320]] ts = [1] + [6] * 16 strides = [1, 2] * 2 + [1, 1, 2] + [1] * 6 + [2] + [1] * 3 for in_c, c, t, s in zip(in_channels_group, channels_group, ts, strides): self.features.append(LinearBottleneck(in_channels=in_c, channels=c, t=t, stride=s)) last_channels = int(1280 * multiplier) if multiplier > 1.0 else 1280 _add_conv(self.features, channels_group[-1], last_channels, relu6=True) self.features = nn.Sequential(*self.features) self.output = nn.Conv2d(last_channels, classes, 1, bias=False)
def __init__(self, in_channels, channels, t, stride, **kwargs): super(LinearBottleneck, self).__init__(**kwargs) self.use_shortcut = stride == 1 and in_channels == channels self.out = list() _add_conv(self.out, in_channels, in_channels * t, relu6=True) _add_conv(self.out, in_channels * t, in_channels * t, kernel=3, stride=stride, pad=1, num_group=in_channels * t, relu6=True) _add_conv(self.out, in_channels * t, channels, active=False, relu6=True) self.out = nn.Sequential(*self.out)