Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Saved model for generating adversarial samples. #189

Open
chamanbanolia opened this issue Jun 19, 2024 · 1 comment
Open

Using Saved model for generating adversarial samples. #189

chamanbanolia opened this issue Jun 19, 2024 · 1 comment

Comments

@chamanbanolia
Copy link

I am not able to create an attack instance when I am using loaded saved model (.pth file) for generating adversarial samples, can you please help find out, what can be the potential issue in this.

Below is the error I am getting

RuntimeError Traceback (most recent call last)
Input In [25], in
1 from torchattacks import FGSM, PGD
----> 3 atk = FGSM(saved_model)
4 print(atk)

File /opt/conda/lib/python3.8/site-packages/torchattacks/attacks/fgsm.py:30, in FGSM.init(self, model, eps)
29 def init(self, model, eps=8 / 255):
---> 30 super().init("FGSM", model)
31 self.eps = eps
32 self.supported_mode = ["default", "targeted"]

File /opt/conda/lib/python3.8/site-packages/torchattacks/attack.py:40, in Attack.init(self, name, model)
37 self.attack = name
38 self._attacks = OrderedDict()
---> 40 self.set_model(model)
41 try:
42 self.device = next(model.parameters()).device

File /opt/conda/lib/python3.8/site-packages/torchattacks/attack.py:10, in wrapper_method..wrapper_func(self, *args, **kwargs)
9 def wrapper_func(self, *args, **kwargs):
---> 10 result = func(self, *args, **kwargs)
11 for atk in self.dict.get("_attacks").values():
12 eval("atk." + func.name + "(*args, **kwargs)")

File /opt/conda/lib/python3.8/site-packages/torchattacks/attack.py:73, in Attack.set_model(self, model)
71 @wrapper_method
72 def set_model(self, model):
---> 73 self.model = model
74 self.model_name = model.class.name

File /opt/conda/lib/python3.8/site-packages/torchattacks/attack.py:563, in Attack.setattr(self, name, value)
560 if isinstance(items, Attack):
561 yield items
--> 563 for num, value in enumerate(get_all_values(value)):
564 attacks[name + "." + str(num)] = value
565 for subname, subvalue in value.dict.get("_attacks").items():

File /opt/conda/lib/python3.8/site-packages/torchattacks/attack.py:555, in Attack.setattr..get_all_values(items, stack)
553 items = list(items.keys()) + list(items.values())
554 for item in items:
--> 555 yield from get_all_values(item, stack)
556 else:
557 if isinstance(items, Attack):

File /opt/conda/lib/python3.8/site-packages/torchattacks/attack.py:549, in Attack.setattr..get_all_values(items, stack)
548 def get_all_values(items, stack=[]):
--> 549 if items not in stack:
550 stack.append(items)
551 if isinstance(items, list) or isinstance(items, dict):

RuntimeError: Boolean value of Tensor with more than one value is ambiguous

@rikonaka
Copy link
Contributor

Hi @chamanbanolia , can you provide your full code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants