Пример #1
0
def init_model_and_train(hidden_size, batch_size, train_size, n_epochs, lr, weight_decay,
            betas0, betas1, seed):
    # Parameters
    num_hidden_layers = 1
    out_channels = 1


    if run_mode == "unfrozen_convolution_relu":
        model = supervised_convnet.SupervisedConvNet(filter_size = 3, square_size = 3, \
                hidden_size = hidden_size, out_channels = out_channels,
                first_activation = "tanh", activation_func = "relu",
                num_hidden_layers = num_hidden_layers, seed = seed)
        results = train.trainer(model = model, batch_size = batch_size, train_size = train_size, n_epochs = n_epochs, lr = lr,
                    weight_decay = weight_decay,
                    betas0 = 1-betas0, betas1 = 1-betas1)
    elif run_mode == "frozen_convolution_no_center_relu":
        model = frozen.SupervisedConvNet(filter_size = 3, square_size = 3, \
                hidden_size = hidden_size, out_channels = out_channels,
                center = "omit", first_activation = "tanh",
                activation_func = "relu", num_hidden_layers = num_hidden_layers)
        results = train.trainer(model = model, batch_size = batch_size, train_size = train_size, n_epochs = n_epochs, lr = lr,
                    weight_decay = weight_decay,
                    betas0 = 1-betas0, betas1 = 1-betas1)
    elif run_mode == "frozen_convolution_pretrained_relu":
        model = frozen.SupervisedConvNet(filter_size = 3, square_size = 3, \
                hidden_size = hidden_size, out_channels = out_channels,
                center = "pre_trained", first_activation = "tanh",
                activation_func = "relu", num_hidden_layers = num_hidden_layers)
        results = train.trainer(model = model, batch_size = batch_size, train_size = train_size, n_epochs = n_epochs, lr = lr,
                    weight_decay = weight_decay,
                    betas0 = 1-betas0, betas1 = 1-betas1)
    elif run_mode == "unfrozen_convolution_3_channels":
        out_channels = 3
        model = supervised_convnet.SupervisedConvNet(filter_size = 3, square_size = 3,
                hidden_size = hidden_size, out_channels = out_channels,
                first_activation = "tanh", activation_func = "relu",
                num_hidden_layers = num_hidden_layers, seed = seed)
        results = train.trainer(model = model, batch_size = batch_size, train_size = train_size, n_epochs = n_epochs, lr = lr,
                    weight_decay = weight_decay,
                    betas0 = 1-betas0, betas1 = 1-betas1)
    return results
Пример #2
0
    conv_params = defaultdict(list)

    if run_mode == "unfrozen_convolution_relu":
        """
        """
        out_channels = 1
        filename = "unfrozen_convolution_relu.pl"
        try:
            with open(filename, "rb") as handle:
                results = pickle.load(handle)
        except:
            results = []
        results = []
        for _ in range(500):
            model = supervised_convnet.SupervisedConvNet(filter_size = 3, square_size = 3, \
                    hidden_size = hidden_size, out_channels = out_channels,
                    first_activation = "tanh", activation_func = "relu",
                    num_hidden_layers = num_hidden_layers, seed = time.time() + _)
            model = model_to_cuda(model)
            best_val_acc, param_dict = train.trainer(
                model=model,
                batch_size=100,
                betas0=1 - 0.0018179320494754046,
                betas1=1 - 0.001354073715524798,
                lr=0.004388469485690077,
                n_epochs=150,
                train_size=5000,
                weight_decay=0,
                use_cuda=use_cuda)
            results.append(best_val_acc)
            conv_params["weight"].append(param_dict["conv1.weight"])
            conv_params["bias"].append(param_dict["conv1.bias"])
Пример #3
0
out_channels = 1
# adjust learning rate?
adjust_learning_rate = False
# GPU?
use_cuda = True

# specify loss function
criterion = nn.BCELoss()

# tensorboard for tracking
writer = SummaryWriter(
    comment="--batch size {}, training set {}, epoch {}, lr {}, \
                        weight decay {}, hidden_size {}, out_channels {}, num_hidden_layers {}"
    .format(batch_size, train_size, n_epochs, lr, weight_decay, hidden_size,
            out_channels, num_hidden_layers))
model = supervised_convnet.SupervisedConvNet(filter_size = 3, square_size = 3, \
        hidden_size = hidden_size, out_channels = out_channels, num_hidden_layers = num_hidden_layers)


def trainer(model=model,
            batch_size=batch_size,
            train_size=train_size,
            n_epochs=n_epochs,
            lr=lr,
            weight_decay=weight_decay,
            adjust_learning_rate=adjust_learning_rate,
            amsgrad=amsgrad,
            betas0=betas0,
            betas1=betas1,
            use_cuda=use_cuda):
    print("Testing out: ")
    print("batch_size: ", batch_size)
Пример #4
0
hidden_size = 10
# adjust learning rate?
adjust_learning_rate = False

# specify loss function
criterion = nn.BCELoss()

# tensorboard for tracking
writer = SummaryWriter(
    comment="--batch size {}, training set {}, epoch {}, lr {}, \
                        weight decay {}, hidden_size {}".format(
        batch_size, train_size, n_epochs, lr, weight_decay, hidden_size))

# build model
model = supervised_convnet.SupervisedConvNet(filter_size=3,
                                             square_size=3,
                                             hidden_size=hidden_size)

# specify optimizer
optimizer = torch.optim.Adam(model.parameters(),
                             lr=lr,
                             weight_decay=weight_decay)

# prepare data loaders
train_isingdataset = supervised_convnet.IsingDataset(X_train[:train_size],
                                                     y_train[:train_size])
train_loader = torch.utils.data.DataLoader(train_isingdataset,
                                           batch_size=batch_size,
                                           num_workers=num_workers,
                                           shuffle=True)