Пример #1
0
def run(nz, n_dense, dataset="mnist", dist_type="perturbed"):
    """
    Constructs a tf.Graph and tf.Session to contain the instance of experiment
    """
    with tf.Graph().as_default():
        config = tf.ConfigProto(device_count={"CPU": 8},
                                intra_op_parallelism_threads=8,
                                inter_op_parallelism_threads=8)
        config.gpu_options.allow_growth = True
        config.gpu_options.visible_device_list = "0"
        with tf.Session(config=config) as sess:
            arguments = {
                # experiment def / paths
                "dataset": dataset,
                "data_dir": os.path.join(ROOT_DIR, "data"),
                "category": -1,
                "dist_type": dist_type,
                "take_frac": 1,
                # model def
                "nz": nz,
                "batch_size": 128,
                "n_dense": n_dense,
                "filters": (4, 8),
                "stride": (1, 1),
                "padding": ("same", "same"),
                "kernel_size": (3, 3),
                "k_samples": 5,
                "sumK": 2,
                "leafK": 2,
                # learner def
                "learning_rate": 0.01,
                "validation_period": 128,
                "strikes": 10
            }

            current_time = int(time.time())

            save_dir = os.path.join(
                MAIN_DIR, "sp_conviwae",
                arguments["dataset"] + "_" + arguments["dist_type"],
                str(arguments["category"]), str(current_time))

            output = sp_conviwae.get_results(save_dir=save_dir, **arguments)

            save_attributes(save_dir, arguments, output)

    return output
Пример #2
0
def run(take_frac, dataset="mnist", dist_type="perturbed"):
    """
    Constructs a tf.Graph and tf.Session to contain the instance of experiment
    """
    if dataset == "mnist" and dist_type == "perturbed":
        nnodes = (32, 32)  # TODO
        nz = 25
    elif dataset == "mnist" and dist_type == "discrete":
        nnodes = (32, 32)  # TODO
        nz = 25
    elif dataset == "svhn" and dist_type == "perturbed":
        nnodes = (32, 32)  # TODO
        nz = 50
    elif dataset == "svhn" and dist_type == "discrete":
        nnodes = (32, 32)  # TODO
        nz = 25
    elif dataset == "cifar10" and dist_type == "perturbed":
        nnodes = (32, 32)  # TODO
        nz = 25
    elif dataset == "cifar10" and dist_type == "discrete":
        nnodes = (32, 32)  # TODO
        nz = 25
    else:
        raise NotImplementedError

    with tf.Graph().as_default():
        config = tf.ConfigProto(device_count={"CPU": 8},
                                intra_op_parallelism_threads=8,
                                inter_op_parallelism_threads=8)
        config.gpu_options.allow_growth = True
        config.gpu_options.visible_device_list = "0"
        with tf.Session(config=config) as sess:
            arguments = {
                # experiment def / paths
                "dataset": dataset,
                "data_dir": os.path.join(ROOT_DIR, "data"),
                "category": -1,
                "dist_type": dist_type,
                "take_frac": take_frac,
                # model def
                "nz": nz,
                "batch_size": 128,
                "nnodes_recog": nnodes,
                "nnodes_gener": nnodes,
                "k_samples": 5,
                "sumK": 2,
                "leafK": 2,
                # learner def
                "learning_rate": 0.01,
                "validation_period": 128,
                "strikes": 10
            }

            current_time = int(time.time())

            save_dir = os.path.join(
                MAIN_DIR, "sp_iwae",
                arguments["dataset"] + "_" + arguments["dist_type"],
                str(arguments["category"]), str(current_time))

            output = sp_iwae.get_results(save_dir=save_dir, **arguments)

            save_attributes(save_dir, arguments, output)

    return output