MCPcopy Index your code
hub / github.com/PyGCL/PyGCL / main

Function main

examples/GRACE.py:75–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73
74
75def main():
76 device = torch.device('cuda')
77 path = osp.join(osp.expanduser('~'), 'datasets')
78 dataset = Planetoid(path, name='Cora', transform=T.NormalizeFeatures())
79 data = dataset[0].to(device)
80
81 aug1 = A.Compose([A.EdgeRemoving(pe=0.3), A.FeatureMasking(pf=0.3)])
82 aug2 = A.Compose([A.EdgeRemoving(pe=0.3), A.FeatureMasking(pf=0.3)])
83
84 gconv = GConv(input_dim=dataset.num_features, hidden_dim=32, activation=torch.nn.ReLU, num_layers=2).to(device)
85 encoder_model = Encoder(encoder=gconv, augmentor=(aug1, aug2), hidden_dim=32, proj_dim=32).to(device)
86 contrast_model = DualBranchContrast(loss=L.InfoNCE(tau=0.2), mode='L2L', intraview_negs=True).to(device)
87
88 optimizer = Adam(encoder_model.parameters(), lr=0.01)
89
90 with tqdm(total=1000, desc='(T)') as pbar:
91 for epoch in range(1, 1001):
92 loss = train(encoder_model, contrast_model, data, optimizer)
93 pbar.set_postfix({'loss': loss})
94 pbar.update()
95
96 test_result = test(encoder_model, data)
97 print(f'(E): Best test F1Mi={test_result["micro_f1"]:.4f}, F1Ma={test_result["macro_f1"]:.4f}')
98
99
100if __name__ == '__main__':

Callers 1

GRACE.pyFile · 0.70

Calls 5

DualBranchContrastClass · 0.90
GConvClass · 0.70
EncoderClass · 0.70
trainFunction · 0.70
testFunction · 0.70

Tested by

no test coverage detected