Ejemplo n.º 1
0
def get_spacegan_config(training_step, prob_config, check_config, cond_input, target):
    model_save_prefix = 'saved_models/'
    # load generator
    gen_model = torch.load(model_save_prefix+"gen_iter " + str(training_step) + ".pkl.gz")

    # load discrimininator
    disc_model = torch.load(model_save_prefix+"disc_iter " + str(training_step) + ".pkl.gz")

    # create a cgan object
    spacegan_i = spacegan_method.SpaceGAN(prob_config, check_config, disc_model, gen_model)

    # get scaling method
    spacegan_i.fit_scaling_method(cond_input, target)

    return spacegan_i
Ejemplo n.º 2
0
        "input_labels"] = spacegan_config.cond_vars + neighbour_list

    # pre-instantiation
    disc_method = spacegan_config.Discriminator(
        spacegan_config.prob_config["output_dim"],
        spacegan_config.prob_config["cond_dim"])
    disc_method.to(spacegan_config.prob_config["device"])
    gen_method = spacegan_config.Generator(
        spacegan_config.prob_config["cond_dim"],
        spacegan_config.prob_config["noise_dim"],
        spacegan_config.prob_config["output_dim"])
    gen_method.to(spacegan_config.prob_config["device"])

    # training SpaceGAN
    spacegan = spacegan_method.SpaceGAN(spacegan_config.prob_config,
                                        spacegan_config.check_config,
                                        disc_method, gen_method)
    spacegan.train(x_train=cond_input, y_train=target, coords=coord_input)
    spacegan.checkpoint_model(spacegan.epochs)  # export final model and data

    # computing metrics
    gan_metrics = spacegan_selection.compute_metrics(
        target, cond_input, spacegan_config.prob_config,
        spacegan_config.check_config, coord_input, spacegan_config.neighbours)

    # selecting and sampling gan
    for criteria in list(spacegan_config.check_config["perf_metrics"].keys()):
        # find best config
        criteria_info = spacegan_config.check_config["pf_metrics_setting"][
            criteria]
        perf_metrics = gan_metrics[criteria_info["metric_level"]]