def __init__(self, code_dim=140, n_class=1000, chn=96, debug=False, use_actnorm=False): super().__init__() self.linear = nn.Linear(n_class, 128, bias=False) if debug: chn = 8 self.first_view = 16 * chn self.G_linear = SpectralNorm(nn.Linear(20, 4 * 4 * 16 * chn)) self.GBlock = nn.ModuleList([ GBlock(16 * chn, 16 * chn, n_class=n_class), GBlock(16 * chn, 8 * chn, n_class=n_class), GBlock(8 * chn, 8 * chn, n_class=n_class), GBlock(8 * chn, 4 * chn, n_class=n_class), GBlock(4 * chn, 2 * chn, n_class=n_class), GBlock(2 * chn, 1 * chn, n_class=n_class), ]) self.sa_id = 5 self.num_split = len(self.GBlock) + 1 self.attention = SelfAttention(2 * chn) if not use_actnorm: self.ScaledCrossReplicaBN = BatchNorm2d(1 * chn, eps=1e-4) else: self.ScaledCrossReplicaBN = ActNorm(1 * chn) self.colorize = SpectralNorm(nn.Conv2d(1 * chn, 3, [3, 3], padding=1))
def __init__(self, num_features, num_classes): super().__init__() self.num_features = num_features self.bn = ActNorm(num_features) self.gamma_embed = SpectralNorm( nn.Linear(num_classes, num_features, bias=False)) self.beta_embed = SpectralNorm( nn.Linear(num_classes, num_features, bias=False))
def __init__(self, code_dim=140, n_class=1000, chn=96, debug=False, use_actnorm=False): super().__init__() if not use_actnorm: import warnings class BatchNormWarning(UserWarning): pass warnings.warn( "You are training with batch norm. It is highly recommended to switch to some " "other normalization method if a low batch size is used. Furthermore, Google may " "sue you for breaking the patent law!", BatchNormWarning) self.linear = nn.Linear(n_class, 128, bias=False) if debug: chn = 8 self.first_view = 16 * chn self.G_linear = SpectralNorm(nn.Linear(20, 4 * 4 * 16 * chn)) self.GBlock = nn.ModuleList([ GBlock(16 * chn, 16 * chn, n_class=n_class, use_actnorm=use_actnorm), GBlock(16 * chn, 8 * chn, n_class=n_class, use_actnorm=use_actnorm), GBlock(8 * chn, 8 * chn, n_class=n_class, use_actnorm=use_actnorm), GBlock(8 * chn, 4 * chn, n_class=n_class, use_actnorm=use_actnorm), GBlock(4 * chn, 2 * chn, n_class=n_class, use_actnorm=use_actnorm), GBlock(2 * chn, 1 * chn, n_class=n_class, use_actnorm=use_actnorm), ]) self.sa_id = 5 self.num_split = len(self.GBlock) + 1 self.attention = SelfAttention(2 * chn) if not use_actnorm: self.ScaledCrossReplicaBN = BatchNorm2d(1 * chn, eps=1e-4) else: self.ScaledCrossReplicaBN = ActNorm(1 * chn) self.colorize = SpectralNorm(nn.Conv2d(1 * chn, 3, [3, 3], padding=1))
def __init__(self, *args, **kwargs): super().__init__() self.bn = ActNorm(*args, **kwargs)