示例#1
0
def download_dataset(dataset):
    cfg = get_cfg()
    cfg.cls.dataset.name = dataset
    dsname = dataset.lower()
    cfg.cls.dataset.root = f"{settings.ROOT_PATH}/data/{dsname}/"
    cfg.cls.dataset.download = True
    get_dataset(cfg, 'cls')
示例#2
0

def test_disent_over_epochs(cfg):
    epoch_num_list = [0, 10, 50, 100, 120, 150]
    for epoch_num in epoch_num_list:
        cfg.disent.epoch_num = epoch_num
        test_disent(cfg)


def plot_th_tensor(ax, i, j, dec_ij):
    dec_ij = dec_ij.to('cpu').detach().numpy()[0, 0]
    ax[i, j].imshow(dec_ij, cmap='Greys_r', interpolation=None)


if __name__ == "__main__":
    cfg = get_cfg()
    cfg.exp_name = "static_noise"

    cfg.disent = edict()
    cfg.disent.epochs = 5000
    cfg.disent.load = False
    cfg.disent.epoch_num = 0

    model_path = Path(f"{settings.ROOT_PATH}/output/disent/{cfg.exp_name}/")
    optim_path = Path(
        f"{settings.ROOT_PATH}/output/disent/{cfg.exp_name}/optim/")
    if not model_path.exists(): model_path.mkdir(parents=True)
    cfg.disent.model_path = model_path
    cfg.disent.optim_path = optim_path

    cfg.disent.workers = 1
示例#3
0
def get_denoising_cfg(args):
    cfg = get_cfg()
    if args.new is True: setup_new_exp(args)

    cfg.cl.device = torch.device("cuda:{}".format(args.gpuid))
    cfg.cls.device = cfg.cl.device

    # set the name
    cfg.exp_name = args.name
    if cfg.exp_name is None:
        cfg.exp_name = str(uuid.uuid4())

    cfg.disent = edict()
    cfg.disent.epochs = 1200
    cfg.disent.device = cfg.cl.device

    cfg.disent.load = args.epoch_num > 0
    cfg.disent.epoch_num = args.epoch_num

    cfg.disent.dataset = edict()
    cfg.disent.dataset.root = f"{settings.ROOT_PATH}/data/"
    cfg.disent.dataset.n_classes = 10
    cfg.disent.dataset.name = args.dataset
    cfg.disent.noise_level = args.noise_level
    cfg.disent.N = args.N
    cfg.disent.img_loss_type = args.img_loss_type
    cfg.disent.share_enc = args.share_enc
    cfg.disent.hyper_h = args.hyper_h
    cfg.disent.lr = edict()
    cfg.disent.lr.start = args.lr_start
    cfg.disent.lr.policy = args.lr_policy
    cfg.disent.lr.params = args.lr_params

    dsname = cfg.disent.dataset.name.lower()
    model_path = Path(
        f"{settings.ROOT_PATH}/output/disent/{dsname}/{cfg.exp_name}")
    optim_path = Path(
        f"{settings.ROOT_PATH}/output/disent/{dsname}/{cfg.exp_name}/optim/")
    if not model_path.exists(): model_path.mkdir(parents=True)
    cfg.disent.model_path = model_path
    cfg.disent.optim_path = optim_path

    cfg.disent.workers = 1
    cfg.disent.batch_size = args.batch_size
    cfg.disent.global_step = 0
    cfg.disent.device = cfg.cl.device
    cfg.disent.current_epoch = 0
    cfg.disent.checkpoint_interval = 1
    cfg.disent.test_interval = 5
    cfg.disent.log_interval = 50
    cfg.disent.random_crop = True

    if cfg.disent.dataset.name.lower() == "mnist":
        cfg.disent.n_channels = 1
    else:
        cfg.disent.n_channels = 3

    cfg.disent.agg_enc_fxn = 'mean'
    if cfg.disent.share_enc is False:
        cfg.disent.agg_enc_fxn = 'id'

    # info = {'noise':args.noise_level,'N':args.N,
    #         'dataset':args.dataset,'batch_size':args.batch_size}
    # write_settings(cfg.exp_name,info)
    # print(info)
    return cfg