# Loss functions adversarial_loss = torch.nn.MSELoss() categorical_loss = torch.nn.CrossEntropyLoss() continuous_loss = torch.nn.MSELoss() # Loss weights lambda_cat = 1 lambda_con = 0.1 # Initialize generator and discriminator categorical_size = config.n_classes if config.n_classes else dataset.n_studies print('categorical_size:', categorical_size) #import ipdb; ipdb.set_trace() generator = Generator(config.latent_dim, categorical_size, config.code_dim, dataset.n_genes) discriminator = Discriminator(categorical_size, config.code_dim, dataset.n_genes) if cuda: generator.cuda() discriminator.cuda() adversarial_loss.cuda() categorical_loss.cuda() continuous_loss.cuda() # Initialize weights generator.apply(weights_init_normal) discriminator.apply(weights_init_normal) # Optimizers
# load config with open(args.config, 'r') as f: y = yaml.load(f, Loader=yaml.SafeLoader) opt = argparse.Namespace(**y) # Loss functions adversarial_loss = torch.nn.MSELoss() categorical_loss = torch.nn.CrossEntropyLoss() continuous_loss = torch.nn.MSELoss() # Loss weights lambda_cat = 1 lambda_con = 0.1 # Initialize generator and discriminator generator = Generator(opt) discriminator = Discriminator(opt) if cuda: generator.cuda() discriminator.cuda() adversarial_loss.cuda() categorical_loss.cuda() continuous_loss.cuda() # Initialize weights generator.apply(weights_init_normal) discriminator.apply(weights_init_normal) # Configure data loader data = CuratedBreastCancerData(opt.batch_size, test_split=0.0) # train this unsupervised model on all data
f.write(arg + '\n') f.close() unloader = transforms.ToPILImage() encoder = Encoder(c_size, z_size) def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: m.weight.data.normal_(0.0, 0.02) elif classname.find('BatchNorm') != -1: m.weight.data.normal_(1.0, 0.02) m.bias.data.fill_(0) g = Generator(c_size + z_size) g.apply(weights_init) d = Discriminator() d.apply(weights_init) q = Q(c_size) q.apply(weights_init) dq = D_Q_commonlayer() dq.apply(weights_init) for i in [dq, d, q, g, encoder]: i.cuda() #i.apply(weights_init) trainer = Trainer(g, dq, d, q, encoder, batch_size, img_size, c_size, z_size,