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

Problem that forward output is tuple rather than tensor #83

Open
momo1986 opened this issue Feb 27, 2022 · 1 comment
Open

Problem that forward output is tuple rather than tensor #83

momo1986 opened this issue Feb 27, 2022 · 1 comment

Comments

@momo1986
Copy link

Hi, dear Frank.

I met the problem caused by PyTorch. The returned forward output is tuple rather than tensor.

I must do operation on output[0] rather than output.

However, the internal code of auto attack is doing on output tensor directly. Is there an auto-attack code version to support the operation to do the execution on the output[0] rather than output? Or should I adjust the PyTorch-Version to support the auto-attack and retrain the model?

Traceback (most recent call last):
File "eval_cifar.py", line 110, in
main()
File "eval_cifar.py", line 107, in main
X_adv = adversary.run_standard_evaluation(x_test, y_test, bs=128)
File "/opt/conda/lib/python3.6/site-packages/autoattack-0.1-py3.6.egg/autoattack/autoattack.py", line 91, in run_standard_evaluation
AttributeError: 'tuple' object has no attribute 'max'

I am looking forward to your answer.

Thanks & Regards!
Momo

@fra31
Copy link
Owner

fra31 commented Feb 27, 2022

Hi,

I think a solution could be to use a wrapper like

class NewModel():
    def __init__(self, model):
        self.model = model

    def __call__(self, x):
        return self.model(x)[0]

on your model, so that it returns only the first element (this is similar to #16).

Hope this helps!

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