DSE-MSU / DeepRobust

A pytorch adversarial library for attack and defense methods on images and graphs
MIT License
994 stars 192 forks source link

Something wrong with `test_nipa.py` #13

Closed thuwzy closed 4 years ago

thuwzy commented 4 years ago

When I directly run test_nipa.py, I got an error like this:

 % python3 test_nipa.py
Namespace(batch_size=10, bilin_q=1, ctx='gpu', dataset='cora', dropout=0.5, gm='mean_field', hidden=0, latent_dim=64, learning_rate=0.01, max_lv=1, meta_test=0, mlp_hidden=64, num_epochs=200, num_mod=1, num_steps=500000, phase='train', ratio=0.01, reward_type='binary', save_dir='./results/rl_s2v/cora-gcn', saved_model='results/node_classification/cora', seed=1, weight_decay=0.0005)
Loading cora dataset...
Dowloading from https://raw.githubusercontent.com/danielzuegner/nettack/master/data/cora.npz to /tmp/cora.npz
Selecting 1 largest connected components
number of injected nodes: 24
Traceback (most recent call last):
  File "test_nipa.py", line 90, in <module>
    features, labels, idx_train, idx_val, idx_test, victim_model, dict_of_lists, adj = init_setup()
  File "test_nipa.py", line 76, in init_setup
    output = victim_model.predict(features, adj)
  File "/xxx/deeprobust/graph/defense/gcn.py", line 215, in predict
    return self.forward(self.features, self.adj_norm)
  File "/xxx/deeprobust/graph/defense/gcn.py", line 87, in forward
    x = F.relu(self.gc1(x, adj))
  File "/xxx/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/xxx/deeprobust/graph/defense/gcn.py", line 43, in forward
    output = torch.spmm(adj, support)
RuntimeError: addmm: Argument #3 (dense): Expected dim 0 size 2485, got 2509
thuwzy commented 4 years ago

In deeprobust/graph/utils.py line 226 and 230, in function to_scipy(tensor), change return sp.csr_matrix((values.cpu().numpy(), indices.cpu().numpy())) into return sp.csr_matrix((values.cpu().numpy(), indices.cpu().numpy()), shape = tensor.shape) may fix it.

ChandlerBang commented 4 years ago

Hi,

Thank you for your valuable advice!

I've modified the to_scipy() as you suggested and fix some extra bugs, like missing __init__.py in deeprobust/graph/rl folder.