DSE-MSU / DeepRobust

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

I got a runtime error #64

Closed lijuancheng closed 3 years ago

lijuancheng commented 3 years ago

Hi Authors,

I would like to repfoduce the results of your paper for my course project. But I keep on getting the error when I run the code.

when I use this command "python train.py --dataset polblogs --attack meta --ptb_rate 0.15 --epoch 1000", I change the dataset setting to "gcn" in the train.py. I got the runtime error. Traceback (most recent call last): File "train.py", line 100, in prognn.fit(features, perturbed_adj, labels, idx_train, idx_val) File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/prognn.py", line 88, in fit self.train_adj(epoch, features, adj, labels, File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/prognn.py", line 169, in train_adj output = self.model(features, normalized_adj) File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/gcn.py", line 124, in forward x = F.relu(self.gc1(x, adj)) File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, **kwargs) File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/gcn.py", line 40, in forward output = torch.spmm(adj, support) RuntimeError: mat1 and mat2 shapes cannot be multiplied (1222x1222 and 1490x16)

And then I used the command "sh scripts/meta/cora_meta.sh", but still got the runtime error.

Traceback (most recent call last): File "train.py", line 100, in prognn.fit(features, perturbed_adj, labels, idx_train, idx_val) File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/prognn.py", line 88, in fit self.train_adj(epoch, features, adj, labels, File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/prognn.py", line 165, in train_adj loss_smooth_feat = self.feature_smoothing(estimator.estimated_adj, features) File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/prognn.py", line 270, in feature_smoothing XLXT = torch.matmul(torch.matmul(X.t(), L), X) RuntimeError: mat1 and mat2 shapes cannot be multiplied (1433x2708 and 2485x2485)

Could you tell me what is the problem? How could I fix it? Thanks so much

ChandlerBang commented 3 years ago

Hi, the pre-attacked graphs are generated under the setting of nettack or prognn where only the largest connected graph is used. Thus, if you want to use the setting of gcn (the full graph), you need to attack the graphs under the gcn setting.

lijuancheng commented 3 years ago

Thanks so much for your reply. I will try to run it again as you said.

Wei Jin @.***>于2021年6月1日 周二下午3:31写道:

Hi, the pre-attacked graphs are generated under the setting of nettack or prognn where only the largest connected graph is used. Thus, if you want to use the setting of gcn (the full graph), you need to attack the graphs under the gcn setting.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DSE-MSU/DeepRobust/issues/64#issuecomment-852526011, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARIO66WLKGOUBHXBTVZKFSLTQVNVNANCNFSM455KOXOQ .

ChandlerBang commented 3 years ago

Hi, I just realized that the prognn setting could not load polblogs dataset correctly. I have fixed that issue and you may now reclone DeepRobust and install it.

git clone https://github.com/DSE-MSU/DeepRobust.git
cd DeepRobust
python setup_empty.py install

Let me know if you have more questions.

lijuancheng commented 3 years ago

Awesome, thanks!

Wei Jin @.***>于2021年6月9日 周三下午5:42写道:

Hi, I just realized that the prognn setting could not load polblogs dataset correctly. I have fixed that issue and you may now reclone DeepRobust and install it.

git clone https://github.com/DSE-MSU/DeepRobust.git cd DeepRobust python setup_empty.py install

Let me know if you have more questions.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DSE-MSU/DeepRobust/issues/64#issuecomment-858194605, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARIO66S6Z5SRYY7W2PQBBKLTSAC6ZANCNFSM455KOXOQ .

lijuancheng commented 3 years ago

Hi Wei,

I did reclone the DeepRobust and install it as you suggested, and then I ran the command "python train.py --dataset polblogs --attack meta --ptb_rate 0.15 --epoch 1000".

But I got the following error.

Traceback (most recent call last):

File "train.py", line 57, in

data = Dataset(root='/tmp/', name=args.dataset, setting='prognn')

File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/data/dataset.py", line 56, in init

assert self.setting in ['gcn', 'nettack'], 'Settings should be gcn or

nettack'

AssertionError: Settings should be gcn or nettack

So I changed the dataset setting to nettack in the train.py, and then I ran the same command "python train.py --dataset polblogs --attack meta --ptb_rate 0.15 --epoch 1000".

But I got another error as follows.

Traceback (most recent call last):

File "train.py", line 100, in

prognn.fit(features, perturbed_adj, labels, idx_train, idx_val)

File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/prognn.py", line 88, in fit

self.train_adj(epoch, features, adj, labels,

File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/prognn.py", line 184, in train_adj

self.optimizer_nuclear.step()

File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/pgd.py", line 64, in step

param.data = prox_operator(param.data, alpha=alpha*lr)

File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/deeprobust/graph/defense/pgd.py", line 84, in prox_nuclear

U, S, V = torch.FloatTensor(U).cuda(), torch.FloatTensor(S).cuda(),

torch.FloatTensor(V).cuda()

File "/Users/lijuan/opt/anaconda3/lib/python3.8/site-packages/torch/cuda/init.py", line 166, in _lazy_init

raise AssertionError("Torch not compiled with CUDA enabled")

AssertionError: Torch not compiled with CUDA enabled

Because I don't have CUDA on my own computer, so what do I need to modify in your code of train.py?

Best,

Lijuan

Wei Jin @.***> 于2021年6月9日周三 下午5:42写道:

Hi, I just realized that the prognn setting could not load polblogs dataset correctly. I have fixed that issue and you may now reclone DeepRobust and install it.

git clone https://github.com/DSE-MSU/DeepRobust.git cd DeepRobust python setup_empty.py install

Let me know if you have more questions.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DSE-MSU/DeepRobust/issues/64#issuecomment-858194605, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARIO66S6Z5SRYY7W2PQBBKLTSAC6ZANCNFSM455KOXOQ .

ChandlerBang commented 3 years ago

Hi,

(1) For the first issue, it seems that you did not successfully reinstall the newest DeepRobust. As in the latest version,

https://github.com/DSE-MSU/DeepRobust/blob/2a52969fb8b881ac5325a8d0a26a6880aa8b6a9b/deeprobust/graph/data/dataset.py#L58-L59

the setting prognn is supported. Please try the following commands again,

pip uninstall deeprobust
git clone https://github.com/DSE-MSU/DeepRobust.git
cd DeepRobust
python setup.py install

(2) For the second issue, I have fixed the issue. You can now run it with CPU after reinstalling the latest DeepRobust.

lijuancheng commented 3 years ago

Hi Wei,

This time it works and can run successfully now. Thank you so much.

Wei Jin @.***> 于2021年6月11日周五 下午5:01写道:

Hi,

(1) For the first issue, it seems that you did not successfully reinstall the newest DeepRobust. As in the latest version,

https://github.com/DSE-MSU/DeepRobust/blob/master/deeprobust/graph/data/dataset.py#L58-L59

the setting prognn is supported. Please try the following commands again,

pip uninstall deeprobust git clone https://github.com/DSE-MSU/DeepRobust.git cd DeepRobust python setup.py install

(2) For the second issue, I have fixed the issue. You can now run it with CPU after reinstalled the latest DeepRobust.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DSE-MSU/DeepRobust/issues/64#issuecomment-859962982, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARIO66SGMRRSO2Z7QYJVATLTSKPWLANCNFSM455KOXOQ .