patience=5, min_lr=0.00001) test_mask = torch.zeros(len(dataset), dtype=torch.uint8) n = len(dataset) // 10 test_mask[i * n:(i + 1) * n] = 1 test_dataset = dataset[test_mask] train_dataset = dataset[1 - test_mask] n = len(train_dataset) // 10 val_mask = torch.zeros(len(train_dataset), dtype=torch.uint8) val_mask[i * n:(i + 1) * n] = 1 val_dataset = train_dataset[val_mask] train_dataset = train_dataset[1 - val_mask] val_loader = DataLoader(val_dataset, batch_size=BATCH) test_loader = DataLoader(test_dataset, batch_size=BATCH) train_loader = DataLoader(train_dataset, batch_size=BATCH, shuffle=True) print('---------------- Split {} ----------------'.format(i)) best_val_loss, test_acc = 100, 0 for epoch in range(1, 101): lr = scheduler.optimizer.param_groups[0]['lr'] train_loss = train(epoch, train_loader, optimizer) val_loss = val(val_loader) scheduler.step(val_loss) if best_val_loss >= val_loss: test_acc = test(test_loader) best_val_loss = val_loss print('Epoch: {:03d}, LR: {:7f}, Train Loss: {:.7f}, '
dataset.data.iso_type_3 = torch.unique(dataset.data.iso_type_3, True, True)[1] num_i_3 = dataset.data.iso_type_3.max().item() + 1 dataset.data.iso_type_3 = one_hot(dataset.data.iso_type_3, num_classes=num_i_3) dataset = dataset.shuffle() # Normalize targets to mean = 0 and std = 1. tenpercent = int(len(dataset) * 0.1) mean = dataset.data.y[tenpercent:].mean(dim=0) std = dataset.data.y[tenpercent:].std(dim=0) dataset.data.y = (dataset.data.y - mean) / std test_dataset = dataset[:tenpercent] val_dataset = dataset[tenpercent:2 * tenpercent] train_dataset = dataset[2 * tenpercent:] test_loader = DataLoader(test_dataset, batch_size=64) val_loader = DataLoader(val_dataset, batch_size=64) train_loader = DataLoader(train_dataset, batch_size=64, shuffle=True) class Net(torch.nn.Module): def __init__(self): super(Net, self).__init__() M_in, M_out = dataset.num_features, 32 nn1 = Sequential(Linear(5, 128), ReLU(), Linear(128, M_in * M_out)) self.conv1 = NNConv(M_in, M_out, nn1) M_in, M_out = M_out, 64 nn2 = Sequential(Linear(5, 128), ReLU(), Linear(128, M_in * M_out)) self.conv2 = NNConv(M_in, M_out, nn2)