def __init__(self, nlatentdim, nClasses, gpu_ids, **kwargs): super(EncD, self).__init__() self.nfc = 1024 self.noise_std = 0 for key in ('noise_std', 'nfc'): if key in kwargs: setattr(self, key, kwargs[key]) self.noise = torch.zeros(0) self.nClasses = nClasses; self.gpu_ids = gpu_ids nfc = self.nfc self.main = nn.Sequential( spectral_norm(nn.Linear(nlatentdim, nfc)), # nn.BatchNorm1d(nfc), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Linear(nfc, nfc)), nn.BatchNorm1d(nfc), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Linear(nfc, 512)), nn.BatchNorm1d(512), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Linear(512, nClasses)) )
def __init__(self, nout, nch, gpu_ids, **kwargs): super(DecD, self).__init__() self.noise_std = 0 for key in ('noise_std'): if key in kwargs: setattr(self, key, kwargs[key]) self.noise = torch.zeros(0) self.gpu_ids = gpu_ids self.fcsize = 2 self.noise = torch.zeros(0) self.start = spectral_norm(nn.Conv2d(nch, 64, ksize, dstep, 1)) layer_sizes = (2**np.arange(6, 12)) layer_sizes[layer_sizes>1024] = 1024 self.poolBlocks = nn.ModuleList([]) self.transitionBlocks = nn.ModuleList([]) for i in range(1, len(layer_sizes)): self.poolBlocks.append(nn.AvgPool2d(2**i, stride=2**i)) self.transitionBlocks.append(nn.Sequential( nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Conv2d(int(layer_sizes[i-1]+nch), int(layer_sizes[i]), ksize, dstep, 1)), nn.BatchNorm2d(int(layer_sizes[i])), )) self.end = nn.LeakyReLU(0.2, inplace=True) self.fc = nn.Linear(1024*int(self.fcsize), nout)
def __init__(self, nLatentDim, nClasses, nRef, nch, gpu_ids): super(Enc, self).__init__() self.gpu_ids = gpu_ids self.fcsize = 2 self.nLatentDim = nLatentDim self.nClasses = nClasses self.nRef = nRef self.main = nn.Sequential( spectral_norm(nn.Conv3d(nch, 64, ksize, dstep, 1)), nn.BatchNorm3d(64), nn.ReLU(inplace=True), spectral_norm(nn.Conv3d(64, 128, ksize, dstep, 1)), nn.BatchNorm3d(128), nn.ReLU(inplace=True), spectral_norm(nn.Conv3d(128, 256, ksize, dstep, 1)), nn.BatchNorm3d(256), nn.ReLU(inplace=True), spectral_norm(nn.Conv3d(256, 512, ksize, dstep, 1)), nn.BatchNorm3d(512), nn.ReLU(inplace=True), spectral_norm(nn.Conv3d(512, 1024, ksize, dstep, 1)), nn.BatchNorm3d(1024), nn.ReLU(inplace=True), spectral_norm(nn.Conv3d(1024, 1024, ksize, dstep, 1)), nn.BatchNorm3d(1024), nn.ReLU(inplace=True) ) if self.nClasses > 0: self.classOut = nn.Sequential( spectral_norm(nn.Linear(1024*int(self.fcsize*1*1), self.nClasses)), # nn.BatchNorm1d(self.nClasses), nn.LogSoftmax() ) if self.nRef > 0: self.refOut = nn.Sequential( spectral_norm(nn.Linear(1024*int(self.fcsize*1*1), self.nRef)), # nn.BatchNorm1d(self.nRef) ) if self.nLatentDim > 0: self.latentOut = nn.Sequential( spectral_norm(nn.Linear(1024*int(self.fcsize*1*1), self.nLatentDim)), # nn.BatchNorm1d(self.nLatentDim) )
def __init__(self, nLatentDim, nClasses, nRef, nch, gpu_ids): super(Enc, self).__init__() self.gpu_ids = gpu_ids self.fcsize = 2 self.nLatentDim = nLatentDim self.nClasses = nClasses self.nRef = nRef self.first = nn.Sequential(nn.Conv3d(nch, 64, ksize, dstep, 1), nn.BatchNorm3d(64), nn.ReLU(inplace=True)) layer_sizes = (2**np.arange(6, 12)) layer_sizes[layer_sizes > 1024] = 1024 self.poolBlocks = nn.ModuleList([]) self.transitionBlocks = nn.ModuleList([]) for i in range(1, len(layer_sizes)): self.poolBlocks.append(nn.AvgPool3d(2**i, stride=2**i)) self.transitionBlocks.append( nn.Sequential( spectral_norm( nn.Conv3d(int(layer_sizes[i - 1] + nch), int(layer_sizes[i]), ksize, dstep, 1)), nn.BatchNorm3d(int(layer_sizes[i])), nn.ReLU(inplace=True), )) if self.nClasses > 0: self.classOut = nn.Sequential( nn.Linear(1024 * int(self.fcsize * 1 * 1), self.nClasses), # nn.BatchNorm1d(self.nClasses), nn.LogSoftmax()) if self.nRef > 0: self.refOut = nn.Sequential( nn.Linear(1024 * int(self.fcsize * 1 * 1), self.nRef), # nn.BatchNorm1d(self.nRef) ) if self.nLatentDim > 0: self.latentOutMu = nn.Sequential( nn.Linear(1024 * int(self.fcsize * 1 * 1), self.nLatentDim)) self.latentOutLogSigma = nn.Sequential( nn.Linear(1024 * int(self.fcsize * 1 * 1), self.nLatentDim))
def __init__(self, nLatentDim, nClasses, nRef, nch, gpu_ids, output_padding=(0, 1, 0)): super(Dec, self).__init__() self.gpu_ids = gpu_ids self.fcsize = 2 self.nLatentDim = nLatentDim self.nClasses = nClasses self.nRef = nRef self.fc = spectral_norm( nn.Linear(self.nLatentDim + self.nClasses + self.nRef, 1024 * int(self.fcsize * 1 * 1))) self.main = nn.Sequential( nn.BatchNorm3d(1024), nn.ReLU(inplace=True), spectral_norm( nn.ConvTranspose3d(1024, 1024, ksize, dstep, 1, output_padding=output_padding)), nn.BatchNorm3d(1024), nn.ReLU(inplace=True), spectral_norm(nn.ConvTranspose3d(1024, 512, ksize, dstep, 1)), nn.BatchNorm3d(512), nn.ReLU(inplace=True), spectral_norm(nn.ConvTranspose3d(512, 256, ksize, dstep, 1)), nn.BatchNorm3d(256), nn.ReLU(inplace=True), spectral_norm(nn.ConvTranspose3d(256, 128, ksize, dstep, 1)), nn.BatchNorm3d(128), nn.ReLU(inplace=True), spectral_norm(nn.ConvTranspose3d(128, 64, ksize, dstep, 1)), nn.BatchNorm3d(64), nn.ReLU(inplace=True), spectral_norm(nn.ConvTranspose3d(64, nch, ksize, dstep, 1)), # nn.BatchNorm3d(nch), nn.Sigmoid())
def __init__(self, nout, nch, gpu_ids, **kwargs): super(DecD, self).__init__() self.noise_std = 0 for key in (['noise_std']): if key in kwargs: setattr(self, key, kwargs[key]) self.noise = torch.zeros(0) self.gpu_ids = gpu_ids self.fcsize = 2 self.noise = torch.zeros(0) self.main = nn.Sequential( spectral_norm(nn.Conv3d(nch, 64, ksize, dstep, 1)), # nn.BatchNorm3d(64), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Conv3d(64, 128, ksize, dstep, 1)), nn.BatchNorm3d(128), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Conv3d(128, 256, ksize, dstep, 1)), nn.BatchNorm3d(256), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Conv3d(256, 512, ksize, dstep, 1)), nn.BatchNorm3d(512), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Conv3d(512, 1024, ksize, dstep, 1)), nn.BatchNorm3d(1024), nn.LeakyReLU(0.2, inplace=True), spectral_norm(nn.Conv3d(1024, 1024, ksize, dstep, 1)), nn.BatchNorm3d(1024), nn.LeakyReLU(0.2, inplace=True) ) self.fc = spectral_norm(nn.Linear(1024*int(self.fcsize), nout))