def main(opt, generator): logger = logging.getLogger("logger") logger.setLevel(logging.DEBUG) handler1 = logging.StreamHandler() handler1.setFormatter( logging.Formatter("%(asctime)s %(levelname)8s %(message)s")) logger.addHandler(handler1) handler2 = logging.FileHandler( filename=os.path.join(opt.loadDir, "is.log")) handler2.setLevel(logging.INFO) handler2.setFormatter(logging.Formatter("%(message)s")) logger.addHandler(handler2) logger.info(opt) np.random.seed(seed=0) #calcurate real dataset IS if opt.calcRealIs: dataset, _ = makeDataloader(opt) IgnoreLabelDataset(dataset) if opt.dataset == 'mnist': calcIS = inception_score(IgnoreLabelDataset(dataset), cuda=cuda, batch_size=32, resize=True, expand=True) else: calcIS = inception_score(IgnoreLabelDataset(dataset), cuda=cuda, batch_size=32, resize=True) logger.info('real, ' + str(calcIS[0])) #calcurate fake dataset init IS calcIS = calcurateInceptionScore(opt, generator.cuda(), str(0)) logger.info('0, ' + str(calcIS[0])) #calcurate fake dataset IS per iter for model_path in sorted( glob.glob(os.path.join(opt.loadDir, 'generator_*'))): name = os.path.basename(model_path) idx = name.replace('generator_model_', '') calcG = generator.cuda() calcG.load_state_dict(torch.load(model_path)) if int(idx) > 0: calcIS = calcurateInceptionScore(opt, calcG, idx) logger.info(str(int(idx)) + ', ' + str(calcIS[0]))
'latent_dim': 128, 'img_size': 32, 'n_critic': 1, 'clip_value': 0.01, 'sample_inNoneterval': 100, 'log_interval': 100, 'modelsave_interval': 1, #per epoch 'dataset': 'mnist', 'num_filters': 128, 'saveDir': None, 'resume': 0, 'logIS': True, 'loadDir': None }) _, dataloader = dataset.makeDataloader(opt) # Initialize generator and discriminator #generator = models.NoiseGenerator2Dv6(opt) #generator = models.MTNoiseGenerator2Dv6(opt) generator = models.NoiseResGenerator2Dv1(opt, noise_layers.NoiseBasicBlock2Dv2, [2, 2, 2, 2, 1], level=0.1) discriminator = naiveresnet.NoiseResNet32(naiveresnet.NoiseBasicBlock, [2, 2, 2, 2], nchannels=1, nfilters=opt.num_filters, nclasses=1, pool=2, level=0.1)