()
| 70 | |
| 71 | |
| 72 | def main(): |
| 73 | device = torch.device('cuda') |
| 74 | path = osp.join(osp.expanduser('~'), 'datasets') |
| 75 | dataset = Planetoid(path, name='Cora', transform=T.NormalizeFeatures()) |
| 76 | data = dataset[0].to(device) |
| 77 | |
| 78 | gconv = GConv(input_dim=dataset.num_features, hidden_dim=512, num_layers=2).to(device) |
| 79 | encoder_model = Encoder(encoder=gconv, hidden_dim=512).to(device) |
| 80 | contrast_model = SingleBranchContrast(loss=L.JSD(), mode='G2L').to(device) |
| 81 | |
| 82 | optimizer = Adam(encoder_model.parameters(), lr=0.01) |
| 83 | |
| 84 | with tqdm(total=300, desc='(T)') as pbar: |
| 85 | for epoch in range(1, 301): |
| 86 | loss = train(encoder_model, contrast_model, data, optimizer) |
| 87 | pbar.set_postfix({'loss': loss}) |
| 88 | pbar.update() |
| 89 | |
| 90 | test_result = test(encoder_model, data) |
| 91 | print(f'(E): Best test F1Mi={test_result["micro_f1"]:.4f}, F1Ma={test_result["macro_f1"]:.4f}') |
| 92 | |
| 93 | |
| 94 | if __name__ == '__main__': |
no test coverage detected