Ejemplo n.º 1
0
            '-'.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,
                               train_valid_loader,
                               test_loader,
                               deepcluster_loader=train_loader)
else:
    data = opt_structures.Data(None,
                               train_unlabeled_loader,
                               None,
# 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')

# Create the step size schedule
if args.step_size_method == 'fixed':
    step_size_schedule = None
    update_step_size_method = 'fixed'
elif args.step_size_method == 'best-ckn-128':

    def step_size_schedule(x):
        if x < 2000:
Ejemplo n.º 3
0
# 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')

# Create the step size schedule
if args.step_size_method == 'fixed':
    step_size_schedule = None
    update_step_size_method = 'fixed'
elif args.step_size_method == 'best-ckn-128':

    def step_size_schedule(x):
        if x < 2000: