Beispiel #1
0
experiment = VAEXperiment(model, config['exp_params'])

runner = Trainer(default_save_path=f"{tt_logger.save_dir}",
                 min_nb_epochs=1,
                 logger=tt_logger,
                 log_save_interval=100,
                 train_percent_check=1.,
                 val_percent_check=1.,
                 num_sanity_val_steps=5,
                 early_stop_callback=False,
                 **config['trainer_params'])

print(f"======= Training {config['model_params']['name']} =======")
load_dict = torch.load(config.ckpt_path)
experiment.load_state_dict(load_dict['state_dict'])
experiment.cuda()
experiment.eval()
sample_dataloader = experiment.train_dataloader()
test_input, test_label = next(iter(sample_dataloader))
#test_input = test_input.to('cuda')
test_label = test_label.to('cuda')
#imgs = experiment.model.sample(num_samples=64, current_device=0)
test_input = scio.loadmat('./cifar10_index.mat')
test_input = torch.Tensor(test_input['data']).to('cuda')
imgs_recon = experiment.model.generate(test_input, labels=test_label)

FID_IS_tf = build_GAN_metric(config.GAN_metric)


class SampleFunc(object):
    def __init__(self, model):
Beispiel #2
0
with open(args.filename, 'r') as file:
    try:
        config = yaml.safe_load(file)
    except yaml.YAMLError as exc:
        print(exc)

with torch.no_grad():
    model = vae_models[config['model_params']['name']](
        **config['model_params'])
    test = VAEXperiment(model, config['exp_params'])
    checkpoint = torch.load(args.ckpt,
                            map_location=lambda storage, loc: storage)
    test.load_state_dict(checkpoint['state_dict'])
    test = test.model
    if args.gpu:
        test = test.cuda()
    if args.eval:
        test.eval()
    if args.parallel:
        test = torch.nn.DataParallel(test)
        test = test.module

xsize = args.xsize
ysize = args.ysize
zsize = args.zsize
blocksize = args.blocksize
dim = args.dimension
error_bound = args.error
eps = args.epsilon
global_max = args.max
global_min = args.min