save_dir = args.save_path
save_file = os.path.join(
    save_dir,
    str(bw) + '_' + str(args.hessian_reg) + '_' + str(args.kernel) + '_' +
    str(args.matern_order) + '_' + str(args.num_filters) + '_' +
    str(args.seed) + '_' + str(args.step_size) + '_' + str(time.time()))

if not os.path.exists(save_dir):
    os.makedirs(save_dir)

# Create the data loaders
train_loader, valid_loader, test_loader = imagenet_subset.get_dataloaders(
    batch_size=args.batch_size, data_path=args.data_path, num_workers=4)

# Load and initialize the model
params = parse_config.load_config('../../cfg/alexnet_ckn.cfg')
num_layers = len(params['num_filters'])
if args.num_filters > 0:
    params['num_filters'] = [args.num_filters] * num_layers
params['patch_sigma'] = [bw] * num_layers
params['patch_kernel'] = [args.kernel] * num_layers
params['matern_order'] = [args.matern_order] * num_layers

layers = parse_config.create_layers(params)
model = net.CKN(layers)
if torch.cuda.device_count() > 1:
    model = nn.DataParallel(model).to(defaults.device)
    model.module.init(train_loader)
else:
    model.to(defaults.device).init(train_loader)
print('Done with the initialization')
Beispiel #2
0
                            batch_size_unlabeled=args.batch_size_unlabeled, num_labeled=args.num_labeled,
                            stratified_sampling=False, stratified_unlabeling=args.balanced, data_path=args.data_path,
                            transform='grad', num_workers=0)

save_dir = args.save_path
save_file = save_dir + str(args.num_labeled) + '_' + str(-1) + '_' + str(args.num_filters) + '_' + str(bw) \
            + '_' + str(args.lr_sup_init) + '_' + str(args.lr_semisup) + '_' + \
            '-'.join(str(args.labeling_method).split(' ')) + '_' + str(args.lam) + '_' + str(args.lambda_pix) + '_' + \
            str(max_frac_points_class) + '_' + str(args.num_clusters) + '_' + str(args.update_clusters_every) + \
            '_' + str(args.seed) + '_' + str(time.time())

if not os.path.exists(save_dir):
    os.makedirs(save_dir)

# Load and initialize the model
params = parse_config.load_config('../../cfg/ckn-gm.cfg')
if args.num_filters > 0:
    nlayers = len(params['num_filters'])
    params['num_filters'] = [args.num_filters] * nlayers
    params['patch_sigma'] = [bw] * nlayers

layers = parse_config.create_layers(params)
model = net.CKN(layers).to(defaults.device)
model.init(train_loader)
print('Done with initialization')

# Set up the data, parameters, model, results, and optimizer objects
if args.num_labeled > 0:
    data = opt_structures.Data(train_labeled_loader,
                               train_unlabeled_loader,
                               valid_loader,
# Create the data loaders
train_loader, train_labeled_loader, train_unlabeled_loader, valid_loader, test_loader = \
    bee_dance.get_dataloaders(batch_size=1, data_path=args.data_path, difference=args.data_difference,
                              num_labeled=args.num_labeled, num_train=args.num_train, num_workers=0,
                              window_size=args.window_size)

if args.bw is None:
    bw = np.median(
        sklearn.metrics.pairwise.pairwise_distances(
            train_loader.dataset.features[0].numpy()).reshape(-1))
    print('Bandwidth from median heuristic:')
else:
    bw = args.bw

# Load and initialize the model
model_params = parse_config.load_config('../../cfg/kn.cfg')
if args.num_filters > 0:
    for key in model_params:
        model_params[key] *= args.num_layers
    model_params['num_filters'] = [args.num_filters] * args.num_layers
    model_params['patch_sigma'] = [bw] * args.num_layers

layers = parse_config.create_layers(model_params)
model = net.CKN(layers).to(defaults.device)
model.init(train_loader)
print('Done with initialization')

# Set up the data, parameters, model, results, and optimizer objects
data = opt_structures.Data(train_labeled_loader, train_unlabeled_loader,
                           valid_loader, test_loader)
params = opt_structures.Params(batch_size=args.batch_size,
Beispiel #4
0
save_dir = args.save_path
save_file = os.path.join(save_dir, str(bw) + '_' + str(args.hessian_reg) + '_' + str(args.num_filters)
                         + '_' + str(args.opt_method) + '_' + str(args.seed) + '_' + str(args.step_size)
                         + '_' + str(time.time()))

if not os.path.exists(save_dir):
    os.makedirs(save_dir)

# Create the data loaders
train_loader, valid_loader, test_loader = mnist.get_dataloaders(batch_size=args.batch_size, data_path=args.data_path,
                                                                num_workers=4)


# Load and initialize the model
params = parse_config.load_config('../../cfg/lenet-5_ckn.cfg')
if args.num_filters > 0:
    num_layers = len(params['num_filters'])
    params['num_filters'] = [args.num_filters] * num_layers
    params['patch_sigma'] = [bw] * num_layers

layers = parse_config.create_layers(params)
model = net.CKN(layers)
if torch.cuda.device_count() > 1:
    model = nn.DataParallel(model).to(defaults.device)
    model.module.init(train_loader)
else:
    model.to(defaults.device).init(train_loader)
print('Done with the initialization')

save_dir = args.save_path
save_file = os.path.join(
    save_dir,
    str(bw) + '_' + str(args.hessian_reg) + '_' + str(args.num_filters) + '_' +
    str(args.num_newton_iters) + '_' + args.opt_method + '_' + str(args.seed) +
    '_' + str(args.step_size) + '_' + str(time.time()))
if not os.path.exists(save_dir):
    os.makedirs(save_dir)

# Create the data loaders
train_loader, valid_loader, test_loader = cifar10.get_dataloaders(
    batch_size=args.batch_size, data_path=args.data_path, num_workers=4)

# Load and initialize the model
params = parse_config.load_config('../../cfg/all-cnn-c_ckn.cfg')
num_layers = len(params['num_filters'])
if args.num_filters > 0:
    params['num_filters'] = [args.num_filters] * num_layers
    params['patch_sigma'] = [bw] * num_layers
    params['precomputed_patches'][0] = True
    params['num_newton_iters'] = [args.num_newton_iters] * num_layers

layers = parse_config.create_layers(params)
model = net.CKN(layers, input_spatial_dims=(32, 32))
if torch.cuda.device_count() > 1:
    model = nn.DataParallel(model).to(defaults.device)
    model.module.init(train_loader)
else:
    model.to(defaults.device).init(train_loader)
print('Done with initialization')