MCPcopy Create free account
hub / github.com/PyGCL/PyGCL / main

Function main

examples/BGRL_G2L.py:160–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

158
159
160def main():
161 device = torch.device('cuda')
162 path = osp.join(osp.expanduser('~'), 'datasets')
163 dataset = TUDataset(path, name='PTC_MR')
164 dataloader = DataLoader(dataset, batch_size=128)
165 input_dim = max(dataset.num_features, 1)
166
167 aug1 = A.Compose([A.EdgeRemoving(pe=0.2), A.FeatureMasking(pf=0.1)])
168 aug2 = A.Compose([A.EdgeRemoving(pe=0.2), A.FeatureMasking(pf=0.1)])
169
170 gconv = GConv(input_dim=input_dim, hidden_dim=32, num_layers=2).to(device)
171 encoder_model = Encoder(encoder=gconv, augmentor=(aug1, aug2), hidden_dim=32).to(device)
172 contrast_model = BootstrapContrast(loss=L.BootstrapLatent(), mode='G2L').to(device)
173
174 optimizer = Adam(encoder_model.parameters(), lr=0.01)
175
176 with tqdm(total=100, desc='(T)') as pbar:
177 for epoch in range(1, 101):
178 loss = train(encoder_model, contrast_model, dataloader, optimizer)
179 pbar.set_postfix({'loss': loss})
180 pbar.update()
181
182 test_result = test(encoder_model, dataloader)
183 print(f'(E): Best test F1Mi={test_result["micro_f1"]:.4f}, F1Ma={test_result["macro_f1"]:.4f}')
184
185
186if __name__ == '__main__':

Callers 1

BGRL_G2L.pyFile · 0.70

Calls 5

BootstrapContrastClass · 0.90
GConvClass · 0.70
EncoderClass · 0.70
trainFunction · 0.70
testFunction · 0.70

Tested by

no test coverage detected