Exemplo n.º 1
0
    salt.to(device)
    for idx in range(1):

        # Setup optimizer
        optimizer = torch.optim.SGD(salt.parameters(),
                                    lr=max_lr,
                                    momentum=momentum,
                                    weight_decay=weight_decay)
        lr_scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(
            optimizer, scheduler_step, min_lr)

        # Load data
        train_id = fold_train[idx]
        val_id = fold_valid[idx]

        X_train, y_train = trainImageFetch(train_id)
        X_val, y_val = trainImageFetch(val_id)

        train_data = DataSource1(X_train,
                                 mode='train',
                                 mask_list=y_train,
                                 fine_size=fine_size,
                                 pad_left=pad_left,
                                 pad_right=pad_right)
        train_loader = DataLoader(train_data,
                                  shuffle=RandomSampler(train_data),
                                  batch_size=batch_size,
                                  num_workers=8,
                                  pin_memory=True)

        val_data = DataSource1(X_val,
Exemplo n.º 2
0
save_weight = '../train_baseline/weights_split/'
max_lr = 0.01
min_lr = 0.001
momentum = 0.9
weight_decay = 1e-4
save_pred = 'predict/'
device = torch.device('cuda' if cuda else 'cpu')

test_id = []
for i in range(5):
    ids = pd.read_csv('../dataset/data_split/test'+str(i)+'.csv')['id'].values
    test_id.append(ids)
if __name__ == '__main__':
    for i in range(5):
        # Load test data
        image_test, _ = trainImageFetch(test_id[i])

        overall_pred = np.zeros((len(test_id[i]), 202, 202), dtype=np.float32)

        # Get model
        salt = EncNet(1)
        salt = salt.to(device)
        pred_null = []
        pred_flip = []
         # Load weight
        param = torch.load(save_weight + weight_name +str(i)+ '.pth')
        salt.load_state_dict(param)
        # Create DataLoader
        test_data = DataSource1(image_test, mode='test', fine_size=fine_size, pad_left=pad_left, pad_right=pad_right)
        test_loader = DataLoader(
                                test_data,