MCPcopy
hub / github.com/THUDM/CogDL / test_fgsm_injection_attack

Function test_fgsm_injection_attack

examples/GRB/test_attack_defense.py:307–335  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

305
306
307def test_fgsm_injection_attack():
308 graph, dataset, test_mask, device, device_ids = init_dataset()
309 model_sur = init_surrogate_model(graph, dataset, test_mask, device, device_ids)
310 model_target = init_target_model(graph, dataset, test_mask, device, device_ids)
311 print("FGSM injection attack...")
312 attack = FGSM(epsilon=0.01,
313 n_epoch=5,
314 n_inject_max=10,
315 n_edge_max=20,
316 feat_lim_min=-1,
317 feat_lim_max=1,
318 early_stop=True,
319 early_stop_patience=2,
320 early_stop_epsilon=1e-4,
321 device=device)
322 graph_attack = attack.attack(model=model_sur,
323 graph=graph,
324 adj_norm_func=GCNAdjNorm)
325 print(graph_attack)
326 test_score_sur = evaluate(model_sur,
327 graph_attack,
328 mask=test_mask,
329 device=device)
330 print("Test score after attack for surrogate model: {:.4f}.".format(test_score_sur))
331 test_score_target_attack = evaluate(model_target,
332 graph_attack,
333 mask=test_mask,
334 device=device)
335 print("Test score after attack for target model: {:.4f}.".format(test_score_target_attack))
336
337
338def test_pgd_injection_attack():

Callers 1

Calls 6

attackMethod · 0.95
evaluateFunction · 0.90
init_datasetFunction · 0.85
init_surrogate_modelFunction · 0.85
init_target_modelFunction · 0.85
FGSMClass · 0.85

Tested by

no test coverage detected